1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -simplifycfg < %s | FileCheck %s
4 ; The branch in the latch do.cond is conditional by a constant and the
5 ; conditional branch replaced by an unconditional one.
6 ; Ensure that the llvm.loop metadata is transferred to the new branch
7 ; (In for.cond.cleanup after further simplifications).
12 @n = dso_local global i32 0, align 4
13 @C = dso_local global i32 0, align 4
15 ; Function Attrs: nounwind
16 define dso_local void @_Z6test01v() addrspace(1) #0 {
17 ; CHECK-LABEL: @_Z6test01v(
19 ; CHECK-NEXT: [[J:%.*]] = alloca i32, align 4
20 ; CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
21 ; CHECK-NEXT: br label [[DO_BODY:%.*]]
23 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* @C, align 4, !tbaa [[TBAA2:![0-9]+]]
24 ; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP0]], 1
25 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[J]] to i8*
26 ; CHECK-NEXT: call addrspace(1) void @llvm.lifetime.start.p0i8(i64 4, i8* [[TMP1]]) #[[ATTR2:[0-9]+]]
27 ; CHECK-NEXT: store i32 0, i32* [[J]], align 4, !tbaa [[TBAA2]]
28 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
30 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* [[J]], align 4, !tbaa [[TBAA2]]
31 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP2]], 3
32 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
33 ; CHECK: for.cond.cleanup:
34 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast i32* [[J]] to i8*
35 ; CHECK-NEXT: call addrspace(1) void @llvm.lifetime.end.p0i8(i64 4, i8* [[TMP3]]) #[[ATTR2]]
36 ; CHECK-NEXT: br label [[DO_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
38 ; CHECK-NEXT: store i32 undef, i32* [[I]], align 4
39 ; CHECK-NEXT: [[TMP4:%.*]] = bitcast i32* [[I]] to i8*
40 ; CHECK-NEXT: call addrspace(1) void @llvm.lifetime.start.p0i8(i64 4, i8* [[TMP4]]) #[[ATTR2]]
41 ; CHECK-NEXT: store i32 0, i32* [[I]], align 4, !tbaa [[TBAA2]]
42 ; CHECK-NEXT: br label [[FOR_COND1:%.*]]
44 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[I]], align 4, !tbaa [[TBAA2]]
45 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* @n, align 4, !tbaa [[TBAA2]]
46 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[TMP5]], [[TMP6]]
47 ; CHECK-NEXT: br i1 [[CMP2]], label [[FOR_BODY4:%.*]], label [[FOR_COND_CLEANUP3:%.*]]
48 ; CHECK: for.cond.cleanup3:
49 ; CHECK-NEXT: [[TMP7:%.*]] = bitcast i32* [[I]] to i8*
50 ; CHECK-NEXT: call addrspace(1) void @llvm.lifetime.end.p0i8(i64 4, i8* [[TMP7]]) #[[ATTR2]]
51 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[J]], align 4, !tbaa [[TBAA2]]
52 ; CHECK-NEXT: [[INC7:%.*]] = add nsw i32 [[TMP8]], 1
53 ; CHECK-NEXT: store i32 [[INC7]], i32* [[J]], align 4, !tbaa [[TBAA2]]
54 ; CHECK-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP8:![0-9]+]]
56 ; CHECK-NEXT: [[TMP9:%.*]] = load i32, i32* [[I]], align 4, !tbaa [[TBAA2]]
57 ; CHECK-NEXT: store volatile i32 [[TMP9]], i32* @C, align 4, !tbaa [[TBAA2]]
58 ; CHECK-NEXT: [[TMP10:%.*]] = load i32, i32* [[I]], align 4, !tbaa [[TBAA2]]
59 ; CHECK-NEXT: [[INC5:%.*]] = add nsw i32 [[TMP10]], 1
60 ; CHECK-NEXT: store i32 [[INC5]], i32* [[I]], align 4, !tbaa [[TBAA2]]
61 ; CHECK-NEXT: br label [[FOR_COND1]], !llvm.loop [[LOOP11:![0-9]+]]
64 %j = alloca i32, align 4
65 %i = alloca i32, align 4
68 do.body: ; preds = %do.cond, %entry
69 %0 = load i32, i32* @C, align 4, !tbaa !2
70 %inc = add nsw i32 %0, 1
71 %1 = bitcast i32* %j to i8*
72 call addrspace(1) void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #2
73 store i32 0, i32* %j, align 4, !tbaa !2
76 for.cond: ; preds = %for.inc6, %do.body
77 %2 = load i32, i32* %j, align 4, !tbaa !2
78 %cmp = icmp slt i32 %2, 3
79 br i1 %cmp, label %for.body, label %for.cond.cleanup
81 for.cond.cleanup: ; preds = %for.cond
82 %3 = bitcast i32* %j to i8*
83 call addrspace(1) void @llvm.lifetime.end.p0i8(i64 4, i8* %3) #2
86 for.body: ; preds = %for.cond
87 store i32 undef, i32* %i, align 4
88 %4 = bitcast i32* %i to i8*
89 call addrspace(1) void @llvm.lifetime.start.p0i8(i64 4, i8* %4) #2
90 store i32 0, i32* %i, align 4, !tbaa !2
93 for.cond1: ; preds = %for.inc, %for.body
94 %5 = load i32, i32* %i, align 4, !tbaa !2
95 %6 = load i32, i32* @n, align 4, !tbaa !2
96 %cmp2 = icmp slt i32 %5, %6
97 br i1 %cmp2, label %for.body4, label %for.cond.cleanup3
99 for.cond.cleanup3: ; preds = %for.cond1
100 %7 = bitcast i32* %i to i8*
101 call addrspace(1) void @llvm.lifetime.end.p0i8(i64 4, i8* %7) #2
104 for.body4: ; preds = %for.cond1
105 %8 = load i32, i32* %i, align 4, !tbaa !2
106 store volatile i32 %8, i32* @C, align 4, !tbaa !2
109 for.inc: ; preds = %for.body4
110 %9 = load i32, i32* %i, align 4, !tbaa !2
111 %inc5 = add nsw i32 %9, 1
112 store i32 %inc5, i32* %i, align 4, !tbaa !2
113 br label %for.cond1, !llvm.loop !6
115 for.end: ; preds = %for.cond.cleanup3
118 for.inc6: ; preds = %for.end
119 %10 = load i32, i32* %j, align 4, !tbaa !2
120 %inc7 = add nsw i32 %10, 1
121 store i32 %inc7, i32* %j, align 4, !tbaa !2
122 br label %for.cond, !llvm.loop !8
124 for.end8: ; preds = %for.cond.cleanup
127 do.cond: ; preds = %for.end8
128 br i1 true, label %do.body, label %do.end, !llvm.loop !10
130 do.end: ; preds = %do.cond
134 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
135 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) addrspace(1) #1
137 ; Function Attrs: argmemonly nofree nosync nounwind willreturn
138 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) addrspace(1) #1
140 attributes #0 = { nounwind "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
141 attributes #1 = { argmemonly nofree nosync nounwind willreturn }
142 attributes #2 = { nounwind }
144 !llvm.module.flags = !{!0}
147 !0 = !{i32 1, !"wchar_size", i32 4}
149 !2 = !{!3, !3, i64 0, i64 4}
150 !3 = !{!4, i64 4, !"int"}
151 !4 = !{!5, i64 1, !"omnipotent char"}
152 !5 = !{!"Simple C++ TBAA"}
153 !6 = distinct !{!6, !7}
154 !7 = !{!"llvm.loop.mustprogress"}
155 !8 = distinct !{!8, !7, !9}
156 !9 = !{!"llvm.loop.unroll.disable"}
157 !10 = distinct !{!10, !11}
158 !11 = !{!"llvm.loop.unroll.count", i32 2}