xref: /llvm-project/llvm/test/Transforms/LICM/sink-instruction-invalid-location.ll (revision c0a986a60f2fe3ec6d0c8be3cc2380e3f3395c7b)
1; RUN: opt --passes=licm -S -o - < %s | FileCheck %s
2
3; Building the test case with `clang -O2 -g` the call to 'getInOrder'
4; on line 16 is sunk out of the loop by LICM.
5; According to 'HowToUpdateDebugInfo' the source location of the sunk
6; call should be dropped.
7
8;  1 __attribute__((noinline)) int getInOrder(int Idx) {
9;  2   static int InOrder[] = { 0, 1 };
10;  3   return InOrder[Idx];
11;  4 }
12;  5
13;  6 __attribute__((noinline)) int getRandVar(int Idx) {
14;  7   static int RandVars[] = { 4, 4 };
15;  8   return RandVars[Idx];
16;  9 }
17; 10
18; 11 int bounce() {
19; 12   int Sum = 0;
20; 13   int Extra = 0;
21; 14   for (int I = 0; I < 2; ++I) {
22; 15     Sum += getRandVar(I);
23; 16     Extra = getInOrder(I);
24; 17     Sum %= 4;
25; 18   }
26; 19   return Sum + Extra;
27; 20 }
28
29; CHECK-LABEL: for.end:
30; CHECK: tail call noundef i32 @getInOrder({{.*}}), !dbg ![[DBG:[0-9]+]]
31; CHECK-DAG: ![[DBG]] = !DILocation(line: 0, scope: ![[SCOPE:[0-9]+]]
32; CHECK-DAG: ![[SCOPE]] = distinct !DISubprogram(name: "bounce",
33
34define noundef i32 @getInOrder(i32 noundef %Idx) #0 !dbg !9 {
35entry:
36  ret i32 2
37}
38
39define noundef i32 @getRandVar(i32 noundef %Idx) #0 !dbg !15 {
40entry:
41  ret i32 4
42}
43
44define noundef i32 @bounce() !dbg !17 {
45entry:
46  br label %for.body, !dbg !20
47
48for.body:                                         ; preds = %entry, %for.body
49  %I.07 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
50  %Sum.06 = phi i32 [ 0, %entry ], [ %rem, %for.body ]
51  %call = tail call noundef i32 @getRandVar(i32 noundef %I.07), !dbg !21
52  %add = add nsw i32 %call, %Sum.06, !dbg !21
53  %call1 = tail call noundef i32 @getInOrder(i32 noundef %I.07), !dbg !22
54  %rem = srem i32 %add, 4, !dbg !23
55  %inc = add nuw nsw i32 %I.07, 1, !dbg !20
56  %cmp = icmp ult i32 %inc, 2, !dbg !20
57  br i1 %cmp, label %for.body, label %for.end, !dbg !20, !llvm.loop !24
58
59for.end:                                          ; preds = %for.body
60  %Sum.0.lcssa = phi i32 [ %rem, %for.body ], !dbg !27
61  %Extra.0.lcssa = phi i32 [ %call1, %for.body ], !dbg !27
62  %add2 = add nsw i32 %Extra.0.lcssa, %Sum.0.lcssa, !dbg !28
63  ret i32 %add2, !dbg !28
64}
65
66attributes #0 = { noinline nounwind willreturn memory(none) }
67
68!llvm.dbg.cu = !{!0}
69!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
70!llvm.ident = !{!8}
71
72!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)
73!1 = !DIFile(filename: "test.cpp", directory: "", checksumkind: CSK_MD5, checksum: "cce1594f8ccf16528cd91ee35b0c1fea")
74!2 = !{i32 2, !"CodeView", i32 1}
75!3 = !{i32 2, !"Debug Info Version", i32 3}
76!4 = !{i32 1, !"wchar_size", i32 2}
77!5 = !{i32 8, !"PIC Level", i32 2}
78!6 = !{i32 7, !"uwtable", i32 2}
79!7 = !{i32 1, !"MaxTLSAlign", i32 65536}
80!8 = !{!"clang version 17.0.0"}
81!9 = distinct !DISubprogram(name: "getInOrder", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
82!10 = !DISubroutineType(types: !11)
83!11 = !{!12, !12}
84!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
85!13 = !{}
86!14 = !DILocation(line: 3, scope: !9)
87!15 = distinct !DISubprogram(name: "getRandVar", scope: !1, file: !1, line: 6, type: !10, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
88!16 = !DILocation(line: 8, scope: !15)
89!17 = distinct !DISubprogram(name: "bounce", scope: !1, file: !1, line: 11, type: !18, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
90!18 = !DISubroutineType(types: !19)
91!19 = !{!12}
92!20 = !DILocation(line: 14, scope: !17)
93!21 = !DILocation(line: 15, scope: !17)
94!22 = !DILocation(line: 16, scope: !17)
95!23 = !DILocation(line: 17, scope: !17)
96!24 = distinct !{!24, !20, !25, !26}
97!25 = !DILocation(line: 18, scope: !17)
98!26 = !{!"llvm.loop.mustprogress"}
99!27 = !DILocation(line: 0, scope: !17)
100!28 = !DILocation(line: 19, scope: !17)
101