blob: 1cd47ebbe38f7e9cfd2fd47866eb9de537d853b2 [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.
5;
6; Test case obtained from the following source code:
7;
8; ////
9; extern int foo(int); // line 1
10;
11; int bar(int X, int *A) {
12; for (int i = 0; i < X; ++i) // line 4
13; A[i] = foo(i);
14;
15; return A[0];
16; }
17; ///
18;
19; Check that the debug location for the loop increment still refers to
20; line 4, column 26, discriminator 2.
21;
22; CHECK-LABEL: for.body:
23; CHECK: [[PHI:%[0-9a-zA-Z.]+]] = phi i64 [
24; CHECK-LABEL: for.inc:
25; CHECK: add nuw nsw i64 [[PHI]], 1, !dbg ![[INDVARMD:[0-9]+]]
26; CHECK-DAG: ![[INDVARMD]] = !DILocation(line: 4, column: 26, scope: ![[INDVARSCOPEMD:[0-9]+]])
27; CHECK-DAG: ![[INDVARSCOPEMD]] = !DILexicalBlockFile(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, discriminator: 2)
28
29target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
30
31define i32 @bar(i32 %X, i32* %A) !dbg !5 {
32entry:
33 %cmp5 = icmp sgt i32 %X, 0, !dbg !7
34 br i1 %cmp5, label %for.body.lr.ph, label %for.end, !dbg !9
35
36for.body.lr.ph:
37 br label %for.body, !dbg !9
38
39for.body:
40 %i.06 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
41 %call = call i32 @foo(i32 %i.06), !dbg !10
42 %idxprom = sext i32 %i.06 to i64, !dbg !11
43 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !11
44 store i32 %call, i32* %arrayidx, align 4, !dbg !12
45 br label %for.inc, !dbg !11
46
47for.inc:
48 %inc = add nsw i32 %i.06, 1, !dbg !13
49 %cmp = icmp slt i32 %inc, %X, !dbg !7
50 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !dbg !9, !llvm.loop !15
51
52for.cond.for.end_crit_edge:
53 br label %for.end, !dbg !9
54
55for.end:
56 %0 = load i32, i32* %A, align 4, !dbg !17
57 ret i32 %0, !dbg !18
58}
59
60declare i32 @foo(i32)
61
62!llvm.dbg.cu = !{!0}
63!llvm.module.flags = !{!3, !4}
64
65!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
66!1 = !DIFile(filename: "test.c", directory: "")
67!2 = !{}
68!3 = !{i32 2, !"Dwarf Version", i32 4}
69!4 = !{i32 2, !"Debug Info Version", i32 3}
70!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)
71!6 = !DISubroutineType(types: !2)
72!7 = !DILocation(line: 4, column: 21, scope: !8)
73!8 = !DILexicalBlockFile(scope: !5, file: !1, discriminator: 1)
74!9 = !DILocation(line: 4, column: 3, scope: !8)
75!10 = !DILocation(line: 5, column: 12, scope: !5)
76!11 = !DILocation(line: 5, column: 5, scope: !5)
77!12 = !DILocation(line: 5, column: 10, scope: !5)
78!13 = !DILocation(line: 4, column: 26, scope: !14)
79!14 = !DILexicalBlockFile(scope: !5, file: !1, discriminator: 2)
80!15 = distinct !{!15, !16}
81!16 = !DILocation(line: 4, column: 3, scope: !5)
82!17 = !DILocation(line: 7, column: 10, scope: !5)
83!18 = !DILocation(line: 7, column: 3, scope: !5)