@@ -28,7 +28,7 @@ if.then: ; preds = %while.body
28
28
br label %if.end
29
29
30
30
; CHECK: if.then:
31
- ; CHECK: br label %while.cond, !llvm.loop !0
31
+ ; CHECK: br label %while.cond, !llvm.loop !1
32
32
33
33
if.else: ; preds = %while.body
34
34
%4 = load i32 , ptr %count , align 4
@@ -37,10 +37,10 @@ if.else: ; preds = %while.body
37
37
br label %if.end
38
38
39
39
; CHECK: if.else:
40
- ; CHECK: br label %while.cond, !llvm.loop !0
40
+ ; CHECK: br label %while.cond, !llvm.loop !1
41
41
42
42
if.end: ; preds = %if.else, %if.then
43
- br label %while.cond , !llvm.loop !0
43
+ br label %while.cond , !llvm.loop !1
44
44
45
45
while.end: ; preds = %while.cond
46
46
ret void
74
74
br label %while.cond
75
75
76
76
while.cond.loopexit: ; preds = %for.body
77
- br label %while.cond , !llvm.loop !2
77
+ br label %while.cond , !llvm.loop !3
78
78
79
79
while.cond: ; preds = %while.cond.loopexit, %entry
80
80
%i.0 = phi i32 [ %a , %entry ], [ %add , %while.cond.loopexit ]
@@ -96,22 +96,74 @@ for.body: ; preds = %while.body, %for.bo
96
96
%1 = tail call i32 asm sideeffect "add ${0:w}, ${1:w}\0A " , "=r,r,~{cc}" (i32 %0 )
97
97
%inc = add nuw nsw i32 %k.07 , 1
98
98
%cmp1 = icmp ult i32 %inc , 5
99
- br i1 %cmp1 , label %for.body , label %while.cond.loopexit , !llvm.loop !4
99
+ br i1 %cmp1 , label %for.body , label %while.cond.loopexit , !llvm.loop !5
100
100
101
101
while.end: ; preds = %while.cond
102
102
%sum.0.lcssa = phi i32 [ %sum.0 , %while.cond ]
103
103
ret i32 %sum.0.lcssa
104
104
}
105
105
106
- !0 = distinct !{!0 , !1 }
107
- !1 = !{!"llvm.loop.distribute.enable" , i1 true }
108
- !2 = distinct !{!2 , !3 }
109
- !3 = !{!"llvm.loop.mustprogress" }
110
- !4 = distinct !{!4 , !3 , !5 }
111
- !5 = !{!"llvm.loop.unroll.enable" }
112
- ; CHECK: !0 = distinct !{!0, !1}
113
- ; CHECK: !1 = !{!"llvm.loop.distribute.enable", i1 true}
114
- ; CHECK: !2 = distinct !{!2, !3}
115
- ; CHECK: !3 = !{!"llvm.loop.mustprogress"}
116
- ; CHECK: !4 = distinct !{!4, !3, !5}
117
- ; CHECK: !5 = !{!"llvm.loop.unroll.enable"}
106
+ ; Test that the condition tested above does not trigger when the loop metadata consists only of debug locations,
107
+ ; i.e.the empty loop latch `while.cond.loopexit` *will* be folded into its successor if its
108
+ ; predecessor blocks are also loop latches and any loop metadata attached to it consists of debug information.
109
+ ;
110
+ define i32 @test3 (i32 %a , i32 %b , i32 %step , i32 %remainder , ptr %input ) !dbg !7 {
111
+ entry:
112
+ br label %while.cond
113
+
114
+ ;CHECK-LABEL: @test3(
115
+ ;CHECK-NOT: while.cond.loopexit
116
+ while.cond.loopexit: ; preds = %for.body
117
+ br label %while.cond , !llvm.loop !10
118
+
119
+ while.cond: ; preds = %while.cond.loopexit, %entry
120
+ %i.0 = phi i32 [ %a , %entry ], [ %add , %while.cond.loopexit ]
121
+ %sum.0 = phi i32 [ 0 , %entry ], [ %1 , %while.cond.loopexit ]
122
+ %sub = sub nsw i32 %b , %i.0
123
+ %cmp = icmp sgt i32 %sub , %remainder
124
+ br i1 %cmp , label %while.body , label %while.end
125
+
126
+ while.body: ; preds = %while.cond
127
+ %add = add nsw i32 %i.0 , %step
128
+ br label %for.body
129
+
130
+ for.body: ; preds = %while.body, %for.body
131
+ %k.07 = phi i32 [ 0 , %while.body ], [ %inc , %for.body ]
132
+ %add2 = add nsw i32 %k.07 , %add
133
+ %idxprom = sext i32 %add2 to i64
134
+ %arrayidx = getelementptr inbounds i32 , ptr %input , i64 %idxprom
135
+ %0 = load i32 , ptr %arrayidx , align 4
136
+ %1 = tail call i32 asm sideeffect "add ${0:w}, ${1:w}\0A " , "=r,r,~{cc}" (i32 %0 )
137
+ %inc = add nuw nsw i32 %k.07 , 1
138
+ %cmp1 = icmp ult i32 %inc , 5
139
+ br i1 %cmp1 , label %for.body , label %while.cond.loopexit , !llvm.loop !5
140
+
141
+ while.end: ; preds = %while.cond
142
+ %sum.0.lcssa = phi i32 [ %sum.0 , %while.cond ]
143
+ ret i32 %sum.0.lcssa
144
+ }
145
+
146
+ !llvm.module.flags = !{!0 }
147
+
148
+ !0 = !{i32 2 , !"Debug Info Version" , i32 3 }
149
+ !1 = distinct !{!1 , !2 }
150
+ !2 = !{!"llvm.loop.distribute.enable" , i1 true }
151
+ !3 = distinct !{!3 , !4 }
152
+ !4 = !{!"llvm.loop.mustprogress" }
153
+ !5 = distinct !{!5 , !4 , !6 }
154
+ !6 = !{!"llvm.loop.unroll.enable" }
155
+ !7 = distinct !DISubprogram (name: "test3" , scope: !8 , file: !8 , spFlags: DISPFlagDefinition, unit: !9 )
156
+ !8 = !DIFile (filename: "preserve-llvm-loop-metadata.ll" , directory: "/" )
157
+ !9 = distinct !DICompileUnit (language: DW_LANG_C99, file: !8 , isOptimized: false , runtimeVersion: 0 , emissionKind: NoDebug)
158
+ !10 = distinct !{!10 , !11 , !13 }
159
+ !11 = !DILocation (line: 8 , column: 4 , scope: !12 )
160
+ !12 = distinct !DILexicalBlock (scope: !7 , file: !8 , line: 8 , column: 2 )
161
+ !13 = !DILocation (line: 9 , column: 23 , scope: !12 )
162
+
163
+ ; CHECK: !1 = distinct !{!1, !2}
164
+ ; CHECK: !2 = !{!"llvm.loop.distribute.enable", i1 true}
165
+ ; CHECK: !3 = distinct !{!3, !4}
166
+ ; CHECK: !4 = !{!"llvm.loop.mustprogress"}
167
+ ; CHECK: !5 = distinct !{!5, !4, !6}
168
+ ; CHECK: !6 = !{!"llvm.loop.unroll.enable"}
169
+ ; CHECK-NOT: !10 = distinct !{!10, !11, !13}
0 commit comments