1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-unroll -unroll-runtime -unroll-allow-remainder -unroll-count=4 -unroll-remainder -S %s -o - | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 @b = common local_unnamed_addr global i32 0, align 4, !dbg !0
7 @a = common local_unnamed_addr global i32* null, align 8, !dbg !6
9 ; Test that loop remainder unrolling doesn't corrupt debuginfo. This example
10 ; used to cause an assert, but also test that the unrolled backwards branches
11 ; have the same DILocation.
13 define i32 @func_c() local_unnamed_addr #0 !dbg !14 {
15 ; CHECK-LABEL: @func_c(
17 ; CHECK-NEXT: [[DOTPR:%.*]] = load i32, i32* @b, align 4, !dbg [[DBG17:![0-9]+]], !tbaa [[TBAA20:![0-9]+]]
18 ; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp eq i32 [[DOTPR]], 0, !dbg [[DBG24:![0-9]+]]
19 ; CHECK-NEXT: br i1 [[TOBOOL1]], label [[FOR_END:%.*]], label [[FOR_BODY_LR_PH:%.*]], !dbg [[DBG24]]
20 ; CHECK: for.body.lr.ph:
21 ; CHECK-NEXT: [[A_PROMOTED:%.*]] = load i32*, i32** @a, align 8, !dbg [[DBG25:![0-9]+]], !tbaa [[TBAA26:![0-9]+]]
22 ; CHECK-NEXT: [[TMP0:%.*]] = sub i32 -2, [[DOTPR]], !dbg [[DBG24]]
23 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[TMP0]], -2, !dbg [[DBG24]]
24 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[DOTPR]], [[TMP1]], !dbg [[DBG24]]
25 ; CHECK-NEXT: [[TMP3:%.*]] = lshr i32 [[TMP0]], 1, !dbg [[DBG24]]
26 ; CHECK-NEXT: [[TMP4:%.*]] = add nuw i32 [[TMP3]], 1, !dbg [[DBG24]]
27 ; CHECK-NEXT: [[XTRAITER:%.*]] = and i32 [[TMP4]], 3, !dbg [[DBG24]]
28 ; CHECK-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0, !dbg [[DBG24]]
29 ; CHECK-NEXT: br i1 [[LCMP_MOD]], label [[FOR_BODY_PROL_PREHEADER:%.*]], label [[FOR_BODY_PROL_LOOPEXIT:%.*]], !dbg [[DBG24]]
30 ; CHECK: for.body.prol.preheader:
31 ; CHECK-NEXT: br label [[FOR_BODY_PROL:%.*]], !dbg [[DBG24]]
32 ; CHECK: for.body.prol:
33 ; CHECK-NEXT: [[ARRAYIDX_PROL:%.*]] = getelementptr inbounds i32, i32* [[A_PROMOTED]], i64 1, !dbg [[DBG28:![0-9]+]]
34 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[ARRAYIDX_PROL]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
35 ; CHECK-NEXT: [[CONV_PROL:%.*]] = sext i32 [[TMP5]] to i64, !dbg [[DBG28]]
36 ; CHECK-NEXT: [[TMP6:%.*]] = inttoptr i64 [[CONV_PROL]] to i32*, !dbg [[DBG28]]
37 ; CHECK-NEXT: [[ADD_PROL:%.*]] = add nsw i32 [[DOTPR]], 2, !dbg [[DBG29:![0-9]+]]
38 ; CHECK-NEXT: [[PROL_ITER_CMP:%.*]] = icmp ne i32 1, [[XTRAITER]], !dbg [[DBG24]]
39 ; CHECK-NEXT: br i1 [[PROL_ITER_CMP]], label [[FOR_BODY_PROL_1:%.*]], label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA:%.*]], !dbg [[DBG24]]
40 ; CHECK: for.body.prol.1:
41 ; CHECK-NEXT: [[ARRAYIDX_PROL_1:%.*]] = getelementptr inbounds i32, i32* [[TMP6]], i64 1, !dbg [[DBG28]]
42 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[ARRAYIDX_PROL_1]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
43 ; CHECK-NEXT: [[CONV_PROL_1:%.*]] = sext i32 [[TMP7]] to i64, !dbg [[DBG28]]
44 ; CHECK-NEXT: [[TMP8:%.*]] = inttoptr i64 [[CONV_PROL_1]] to i32*, !dbg [[DBG28]]
45 ; CHECK-NEXT: [[ADD_PROL_1:%.*]] = add nsw i32 [[ADD_PROL]], 2, !dbg [[DBG29]]
46 ; CHECK-NEXT: [[PROL_ITER_CMP_1:%.*]] = icmp ne i32 2, [[XTRAITER]], !dbg [[DBG24]]
47 ; CHECK-NEXT: br i1 [[PROL_ITER_CMP_1]], label [[FOR_BODY_PROL_2:%.*]], label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]], !dbg [[DBG24]]
48 ; CHECK: for.body.prol.2:
49 ; CHECK-NEXT: [[ARRAYIDX_PROL_2:%.*]] = getelementptr inbounds i32, i32* [[TMP8]], i64 1, !dbg [[DBG28]]
50 ; CHECK-NEXT: [[TMP9:%.*]] = load i32, i32* [[ARRAYIDX_PROL_2]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
51 ; CHECK-NEXT: [[CONV_PROL_2:%.*]] = sext i32 [[TMP9]] to i64, !dbg [[DBG28]]
52 ; CHECK-NEXT: [[TMP10:%.*]] = inttoptr i64 [[CONV_PROL_2]] to i32*, !dbg [[DBG28]]
53 ; CHECK-NEXT: [[ADD_PROL_2:%.*]] = add nsw i32 [[ADD_PROL_1]], 2, !dbg [[DBG29]]
54 ; CHECK-NEXT: br label [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]]
55 ; CHECK: for.body.prol.loopexit.unr-lcssa:
56 ; CHECK-NEXT: [[DOTLCSSA_UNR_PH:%.*]] = phi i32* [ [[TMP6]], [[FOR_BODY_PROL]] ], [ [[TMP8]], [[FOR_BODY_PROL_1]] ], [ [[TMP10]], [[FOR_BODY_PROL_2]] ]
57 ; CHECK-NEXT: [[DOTUNR_PH:%.*]] = phi i32* [ [[TMP6]], [[FOR_BODY_PROL]] ], [ [[TMP8]], [[FOR_BODY_PROL_1]] ], [ [[TMP10]], [[FOR_BODY_PROL_2]] ]
58 ; CHECK-NEXT: [[DOTUNR1_PH:%.*]] = phi i32 [ [[ADD_PROL]], [[FOR_BODY_PROL]] ], [ [[ADD_PROL_1]], [[FOR_BODY_PROL_1]] ], [ [[ADD_PROL_2]], [[FOR_BODY_PROL_2]] ]
59 ; CHECK-NEXT: br label [[FOR_BODY_PROL_LOOPEXIT]], !dbg [[DBG24]]
60 ; CHECK: for.body.prol.loopexit:
61 ; CHECK-NEXT: [[DOTLCSSA_UNR:%.*]] = phi i32* [ undef, [[FOR_BODY_LR_PH]] ], [ [[DOTLCSSA_UNR_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ]
62 ; CHECK-NEXT: [[DOTUNR:%.*]] = phi i32* [ [[A_PROMOTED]], [[FOR_BODY_LR_PH]] ], [ [[DOTUNR_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ]
63 ; CHECK-NEXT: [[DOTUNR1:%.*]] = phi i32 [ [[DOTPR]], [[FOR_BODY_LR_PH]] ], [ [[DOTUNR1_PH]], [[FOR_BODY_PROL_LOOPEXIT_UNR_LCSSA]] ]
64 ; CHECK-NEXT: [[TMP11:%.*]] = icmp ult i32 [[TMP3]], 3, !dbg [[DBG24]]
65 ; CHECK-NEXT: br i1 [[TMP11]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY_LR_PH_NEW:%.*]], !dbg [[DBG24]]
66 ; CHECK: for.body.lr.ph.new:
67 ; CHECK-NEXT: br label [[FOR_BODY:%.*]], !dbg [[DBG24]]
69 ; CHECK-NEXT: [[TMP12:%.*]] = phi i32* [ [[DOTUNR]], [[FOR_BODY_LR_PH_NEW]] ], [ [[TMP21:%.*]], [[FOR_BODY]] ], !dbg [[DBG28]]
70 ; CHECK-NEXT: [[TMP13:%.*]] = phi i32 [ [[DOTUNR1]], [[FOR_BODY_LR_PH_NEW]] ], [ [[ADD_3:%.*]], [[FOR_BODY]] ]
71 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[TMP12]], i64 1, !dbg [[DBG28]]
72 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, i32* [[ARRAYIDX]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
73 ; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[TMP14]] to i64, !dbg [[DBG28]]
74 ; CHECK-NEXT: [[TMP15:%.*]] = inttoptr i64 [[CONV]] to i32*, !dbg [[DBG28]]
75 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP13]], 2, !dbg [[DBG29]]
76 ; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds i32, i32* [[TMP15]], i64 1, !dbg [[DBG28]]
77 ; CHECK-NEXT: [[TMP16:%.*]] = load i32, i32* [[ARRAYIDX_1]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
78 ; CHECK-NEXT: [[CONV_1:%.*]] = sext i32 [[TMP16]] to i64, !dbg [[DBG28]]
79 ; CHECK-NEXT: [[TMP17:%.*]] = inttoptr i64 [[CONV_1]] to i32*, !dbg [[DBG28]]
80 ; CHECK-NEXT: [[ADD_1:%.*]] = add nsw i32 [[ADD]], 2, !dbg [[DBG29]]
81 ; CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds i32, i32* [[TMP17]], i64 1, !dbg [[DBG28]]
82 ; CHECK-NEXT: [[TMP18:%.*]] = load i32, i32* [[ARRAYIDX_2]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
83 ; CHECK-NEXT: [[CONV_2:%.*]] = sext i32 [[TMP18]] to i64, !dbg [[DBG28]]
84 ; CHECK-NEXT: [[TMP19:%.*]] = inttoptr i64 [[CONV_2]] to i32*, !dbg [[DBG28]]
85 ; CHECK-NEXT: [[ADD_2:%.*]] = add nsw i32 [[ADD_1]], 2, !dbg [[DBG29]]
86 ; CHECK-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr inbounds i32, i32* [[TMP19]], i64 1, !dbg [[DBG28]]
87 ; CHECK-NEXT: [[TMP20:%.*]] = load i32, i32* [[ARRAYIDX_3]], align 4, !dbg [[DBG28]], !tbaa [[TBAA20]]
88 ; CHECK-NEXT: [[CONV_3:%.*]] = sext i32 [[TMP20]] to i64, !dbg [[DBG28]]
89 ; CHECK-NEXT: [[TMP21]] = inttoptr i64 [[CONV_3]] to i32*, !dbg [[DBG28]]
90 ; CHECK-NEXT: [[ADD_3]] = add nsw i32 [[ADD_2]], 2, !dbg [[DBG29]]
91 ; CHECK-NEXT: [[TOBOOL_3:%.*]] = icmp eq i32 [[ADD_3]], 0, !dbg [[DBG24]]
92 ; CHECK-NEXT: br i1 [[TOBOOL_3]], label [[FOR_COND_FOR_END_CRIT_EDGE_UNR_LCSSA:%.*]], label [[FOR_BODY]], !dbg [[DBG24]], !llvm.loop [[LOOP30:![0-9]+]]
93 ; CHECK: for.cond.for.end_crit_edge.unr-lcssa:
94 ; CHECK-NEXT: [[DOTLCSSA_PH:%.*]] = phi i32* [ [[TMP21]], [[FOR_BODY]] ]
95 ; CHECK-NEXT: br label [[FOR_COND_FOR_END_CRIT_EDGE]], !dbg [[DBG24]]
96 ; CHECK: for.cond.for.end_crit_edge:
97 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i32* [ [[DOTLCSSA_UNR]], [[FOR_BODY_PROL_LOOPEXIT]] ], [ [[DOTLCSSA_PH]], [[FOR_COND_FOR_END_CRIT_EDGE_UNR_LCSSA]] ], !dbg [[DBG28]]
98 ; CHECK-NEXT: [[TMP22:%.*]] = add i32 [[TMP2]], 2, !dbg [[DBG24]]
99 ; CHECK-NEXT: store i32* [[DOTLCSSA]], i32** @a, align 8, !dbg [[DBG25]], !tbaa [[TBAA26]]
100 ; CHECK-NEXT: store i32 [[TMP22]], i32* @b, align 4, !dbg [[DBG33:![0-9]+]], !tbaa [[TBAA20]]
101 ; CHECK-NEXT: br label [[FOR_END]], !dbg [[DBG24]]
103 ; CHECK-NEXT: ret i32 undef, !dbg [[DBG34:![0-9]+]]
106 %.pr = load i32, i32* @b, align 4, !dbg !17, !tbaa !20
107 %tobool1 = icmp eq i32 %.pr, 0, !dbg !24
108 br i1 %tobool1, label %for.end, label %for.body.lr.ph, !dbg !24
111 %a.promoted = load i32*, i32** @a, align 8, !dbg !25, !tbaa !26
112 %0 = sub i32 -2, %.pr, !dbg !24
113 %1 = and i32 %0, -2, !dbg !24
114 %2 = add i32 %.pr, %1, !dbg !24
115 br label %for.body, !dbg !24
118 %3 = phi i32* [ %a.promoted, %for.body.lr.ph ], [ %6, %for.body ], !dbg !28
119 %4 = phi i32 [ %.pr, %for.body.lr.ph ], [ %add, %for.body ]
120 %arrayidx = getelementptr inbounds i32, i32* %3, i64 1, !dbg !28
121 %5 = load i32, i32* %arrayidx, align 4, !dbg !28, !tbaa !20
122 %conv = sext i32 %5 to i64, !dbg !28
123 %6 = inttoptr i64 %conv to i32*, !dbg !28
124 %add = add nsw i32 %4, 2, !dbg !29
125 %tobool = icmp eq i32 %add, 0, !dbg !24
126 br i1 %tobool, label %for.cond.for.end_crit_edge, label %for.body, !dbg !24, !llvm.loop !30
128 for.cond.for.end_crit_edge:
129 %7 = add i32 %2, 2, !dbg !24
130 store i32* %6, i32** @a, align 8, !dbg !25, !tbaa !26
131 store i32 %7, i32* @b, align 4, !dbg !32, !tbaa !20
132 br label %for.end, !dbg !24
135 ret i32 undef, !dbg !33
138 define void @func_d() local_unnamed_addr #1 !dbg !34 {
140 ; CHECK-LABEL: @func_d(
142 ; CHECK-NEXT: ret void, !dbg [[DBG38:![0-9]+]]
148 attributes #0 = { norecurse nounwind uwtable }
149 attributes #0 = { norecurse nounwind readnone uwtable }
152 !llvm.module.flags = !{!10, !11, !12}
155 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
156 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
157 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
158 !3 = !DIFile(filename: "loop.c", directory: "/work/projects/src/tests/unroll-debug-info")
161 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
162 !7 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
163 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
164 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
165 !10 = !{i32 2, !"Dwarf Version", i32 4}
166 !11 = !{i32 2, !"Debug Info Version", i32 3}
167 !12 = !{i32 1, !"wchar_size", i32 4}
168 !13 = !{!"clang version 6.0.0"}
169 !14 = distinct !DISubprogram(name: "c", scope: !3, file: !3, line: 3, type: !15, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, retainedNodes: !4)
170 !15 = !DISubroutineType(types: !16)
172 !17 = !DILocation(line: 4, column: 12, scope: !18)
173 !18 = distinct !DILexicalBlock(scope: !19, file: !3, line: 4, column: 5)
174 !19 = distinct !DILexicalBlock(scope: !14, file: !3, line: 4, column: 5)
175 !20 = !{!21, !21, i64 0}
176 !21 = !{!"int", !22, i64 0}
177 !22 = !{!"omnipotent char", !23, i64 0}
178 !23 = !{!"Simple C/C++ TBAA"}
179 !24 = !DILocation(line: 4, column: 5, scope: !19)
180 !25 = !DILocation(line: 5, column: 13, scope: !18)
181 !26 = !{!27, !27, i64 0}
182 !27 = !{!"any pointer", !22, i64 0}
183 !28 = !DILocation(line: 5, column: 15, scope: !18)
184 !29 = !DILocation(line: 4, column: 21, scope: !18)
185 !30 = distinct !{!30, !24, !31}
186 !31 = !DILocation(line: 5, column: 18, scope: !19)
187 !32 = !DILocation(line: 4, column: 17, scope: !18)
188 !33 = !DILocation(line: 6, column: 1, scope: !14)
189 !34 = distinct !DISubprogram(name: "d", scope: !3, file: !3, line: 7, type: !35, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !2, retainedNodes: !4)
190 !35 = !DISubroutineType(types: !36)
192 !37 = !DILocation(line: 7, column: 11, scope: !34)