blob: f27250a38c0069d02863a369bf057491393e3888 [file] [log] [blame]
Andrea Di Biagio824cabd2016-10-25 16:45:17 +00001; RUN: opt -indvars -S < %s | FileCheck %s
2;
3; When the induction variable is widened by indvars, check that the debug loc
4; associated with the loop increment is correctly propagated.
Andrea Di Biagio9bcb0642016-10-26 10:28:32 +00005; Also, when the exit condition of a loop is rewritten to be a canonical !=
6; comparison, check that the debug loc of the orginal comparison is reused.
Andrea Di Biagio824cabd2016-10-25 16:45:17 +00007;
8; Test case obtained from the following source code:
9;
10; ////
11; extern int foo(int); // line 1
12;
13; int bar(int X, int *A) {
14; for (int i = 0; i < X; ++i) // line 4
15; A[i] = foo(i);
16;
17; return A[0];
18; }
19; ///
20;
21; Check that the debug location for the loop increment still refers to
22; line 4, column 26, discriminator 2.
23;
Andrea Di Biagio9bcb0642016-10-26 10:28:32 +000024; Check that the canonicalized compare instruction for the loop exit
25; condition still refers to line 4, column 21, discriminator 1.
26;
Andrea Di Biagio824cabd2016-10-25 16:45:17 +000027; CHECK-LABEL: for.body:
28; CHECK: [[PHI:%[0-9a-zA-Z.]+]] = phi i64 [
29; CHECK-LABEL: for.inc:
30; CHECK: add nuw nsw i64 [[PHI]], 1, !dbg ![[INDVARMD:[0-9]+]]
Andrea Di Biagio9bcb0642016-10-26 10:28:32 +000031; CHECK: icmp ne i64 %{{.+}}, %{{.+}}, !dbg ![[ICMPMD:[0-9]+]]
32; CHECK-DAG: ![[ICMPMD]] = !DILocation(line: 4, column: 21, scope: ![[ICMPSCOPEMD:[0-9]+]]
33; CHECK-DAG: ![[ICMPSCOPEMD]] = !DILexicalBlockFile(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, discriminator: 1)
Andrea Di Biagio824cabd2016-10-25 16:45:17 +000034; CHECK-DAG: ![[INDVARMD]] = !DILocation(line: 4, column: 26, scope: ![[INDVARSCOPEMD:[0-9]+]])
35; CHECK-DAG: ![[INDVARSCOPEMD]] = !DILexicalBlockFile(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, discriminator: 2)
36
37target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
38
39define i32 @bar(i32 %X, i32* %A) !dbg !5 {
40entry:
41 %cmp5 = icmp sgt i32 %X, 0, !dbg !7
42 br i1 %cmp5, label %for.body.lr.ph, label %for.end, !dbg !9
43
44for.body.lr.ph:
45 br label %for.body, !dbg !9
46
47for.body:
48 %i.06 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
49 %call = call i32 @foo(i32 %i.06), !dbg !10
50 %idxprom = sext i32 %i.06 to i64, !dbg !11
51 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !11
52 store i32 %call, i32* %arrayidx, align 4, !dbg !12
53 br label %for.inc, !dbg !11
54
55for.inc:
56 %inc = add nsw i32 %i.06, 1, !dbg !13
57 %cmp = icmp slt i32 %inc, %X, !dbg !7
58 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !dbg !9, !llvm.loop !15
59
60for.cond.for.end_crit_edge:
61 br label %for.end, !dbg !9
62
63for.end:
64 %0 = load i32, i32* %A, align 4, !dbg !17
65 ret i32 %0, !dbg !18
66}
67
68declare i32 @foo(i32)
69
70!llvm.dbg.cu = !{!0}
71!llvm.module.flags = !{!3, !4}
72
73!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
74!1 = !DIFile(filename: "test.c", directory: "")
75!2 = !{}
76!3 = !{i32 2, !"Dwarf Version", i32 4}
77!4 = !{i32 2, !"Debug Info Version", i32 3}
78!5 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !6, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
79!6 = !DISubroutineType(types: !2)
80!7 = !DILocation(line: 4, column: 21, scope: !8)
81!8 = !DILexicalBlockFile(scope: !5, file: !1, discriminator: 1)
82!9 = !DILocation(line: 4, column: 3, scope: !8)
83!10 = !DILocation(line: 5, column: 12, scope: !5)
84!11 = !DILocation(line: 5, column: 5, scope: !5)
85!12 = !DILocation(line: 5, column: 10, scope: !5)
86!13 = !DILocation(line: 4, column: 26, scope: !14)
87!14 = !DILexicalBlockFile(scope: !5, file: !1, discriminator: 2)
88!15 = distinct !{!15, !16}
89!16 = !DILocation(line: 4, column: 3, scope: !5)
90!17 = !DILocation(line: 7, column: 10, scope: !5)
91!18 = !DILocation(line: 7, column: 3, scope: !5)