1; RUN: opt < %s -gvn -S | FileCheck %s
2; CHECK: {{^}}for.body:
3; CHECK-NEXT: [[VREG1:%[^ ]+]] = phi{{.*}}[[VREG2:%[^ ]+]],{{.*}}%.sink,
4; CHECK-NOT: !dbg
5; CHECK-SAME: {{$}}
6; CHECK: {{^}}for.inc:
7; CHECK-NEXT: [[VREG2]] = phi{{.*}}%inc,{{.*}}[[VREG1]]
8
9target triple = "x86_64-unknown-linux-gnu"
10
11@g = external local_unnamed_addr global i32, align 4
12
13; Function Attrs: nounwind uwtable
14define void @foo(i32 %x, i32 %y, i32 %z) local_unnamed_addr #0 !dbg !4 {
15entry:
16  %not.tobool = icmp eq i32 %x, 0, !dbg !8
17  %.sink = zext i1 %not.tobool to i32, !dbg !8
18  store i32 %.sink, i32* @g, align 4, !tbaa !9
19  %cmp8 = icmp sgt i32 %y, 0, !dbg !13
20  br i1 %cmp8, label %for.body.preheader, label %for.end, !dbg !17
21
22for.body.preheader:                               ; preds = %entry
23  br label %for.body, !dbg !19
24
25for.body:                                         ; preds = %for.body.preheader, %for.inc
26  %i.09 = phi i32 [ %inc4, %for.inc ], [ 0, %for.body.preheader ]
27  %cmp1 = icmp sgt i32 %i.09, %z, !dbg !19
28  br i1 %cmp1, label %if.then2, label %for.inc, !dbg !21
29
30if.then2:                                         ; preds = %for.body
31  %0 = load i32, i32* @g, align 4, !dbg !22, !tbaa !9
32  %inc = add nsw i32 %0, 1, !dbg !22
33  store i32 %inc, i32* @g, align 4, !dbg !22, !tbaa !9
34  br label %for.inc, !dbg !23
35
36for.inc:                                          ; preds = %for.body, %if.then2
37  %inc4 = add nuw nsw i32 %i.09, 1, !dbg !24
38  %exitcond = icmp ne i32 %inc4, %y, !dbg !13
39  br i1 %exitcond, label %for.body, label %for.end.loopexit, !dbg !17
40
41for.end.loopexit:                                 ; preds = %for.inc
42  br label %for.end, !dbg !26
43
44for.end:                                          ; preds = %for.end.loopexit, %entry
45  ret void, !dbg !26
46}
47
48!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
49!1 = !DIFile(filename: "foo.c", directory: "b/")
50!2 = !{i32 2, !"Dwarf Version", i32 4}
51!3 = !{i32 2, !"Debug Info Version", i32 3}
52!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
53!5 = !DISubroutineType(types: !6)
54!6 = !{null, !7, !7, !7}
55!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
56!8 = !DILocation(line: 4, column: 7, scope: !4)
57!9 = !{!10, !10, i64 0}
58!10 = !{!"int", !11, i64 0}
59!11 = !{!"omnipotent char", !12, i64 0}
60!12 = !{!"Simple C/C++ TBAA"}
61!13 = !DILocation(line: 10, column: 13, scope: !14)
62!14 = !DILexicalBlockFile(scope: !15, file: !1, discriminator: 1)
63!15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 10, column: 3)
64!16 = distinct !DILexicalBlock(scope: !4, file: !1, line: 10, column: 3)
65!17 = !DILocation(line: 10, column: 3, scope: !18)
66!18 = !DILexicalBlockFile(scope: !16, file: !1, discriminator: 1)
67!19 = !DILocation(line: 11, column: 11, scope: !20)
68!20 = distinct !DILexicalBlock(scope: !15, file: !1, line: 11, column: 9)
69!21 = !DILocation(line: 11, column: 9, scope: !15)
70!22 = !DILocation(line: 12, column: 8, scope: !20)
71!23 = !DILocation(line: 12, column: 7, scope: !20)
72!24 = !DILocation(line: 10, column: 20, scope: !25)
73!25 = !DILexicalBlockFile(scope: !15, file: !1, discriminator: 2)
74!26 = !DILocation(line: 13, column: 1, scope: !4)
75
76!llvm.dbg.cu = !{!0}
77!llvm.module.flags = !{!2, !3}
78