1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
3 ; The test is to check redundency produced by loop unroll pass
4 ; should be cleaned up by later pass.
5 ; RUN: opt < %s -O2 -S | FileCheck %s
8 ; %dec18 = add nsw i32 %dec18.in, -1
10 ; %dec18.1 = add nsw i32 %dec18, -1
11 ; should be merged to:
12 ; %dec18.1 = add nsw i32 %dec18.in, -2
15 ; ModuleID = '<stdin>'
16 target triple = "x86_64-unknown-linux-gnu"
18 @b = global i32 0, align 4
19 @c = global i32 0, align 4
21 ; Function Attrs: nounwind uwtable
22 define void @_Z3fn1v(ptr %r, ptr %a) #0 {
23 ; CHECK-LABEL: define void @_Z3fn1v(
24 ; CHECK-SAME: ptr nocapture writeonly [[R:%.*]], ptr nocapture readonly [[A:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
25 ; CHECK-NEXT: [[ENTRY:.*]]:
26 ; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr @b, align 4
27 ; CHECK-NEXT: [[TOBOOL20:%.*]] = icmp eq i32 [[TMP]], 0
28 ; CHECK-NEXT: br i1 [[TOBOOL20]], label %[[FOR_END6:.*]], label %[[FOR_BODY:.*]]
29 ; CHECK: [[FOR_COND_LOOPEXIT_LOOPEXIT:.*]]:
30 ; CHECK-NEXT: [[ADD_PTR_LCSSA:%.*]] = phi ptr [ [[ADD_PTR_LCSSA_UNR:%.*]], %[[FOR_BODY3_PROL_LOOPEXIT:.*]] ], [ [[ADD_PTR_1:%.*]], %[[FOR_INC_1:.*]] ]
31 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[A_021:%.*]], i64 1
32 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[SCEVGEP]], i64 [[TMP1:%.*]]
33 ; CHECK-NEXT: [[TMP1_PRE:%.*]] = load i32, ptr @b, align 4
34 ; CHECK-NEXT: br label %[[FOR_COND_LOOPEXIT:.*]]
35 ; CHECK: [[FOR_COND_LOOPEXIT]]:
36 ; CHECK-NEXT: [[T1:%.*]] = phi i32 [ [[T12:%.*]], %[[FOR_BODY]] ], [ [[TMP1_PRE]], %[[FOR_COND_LOOPEXIT_LOOPEXIT]] ]
37 ; CHECK-NEXT: [[R_1_LCSSA:%.*]] = phi ptr [ [[R_022:%.*]], %[[FOR_BODY]] ], [ [[ADD_PTR_LCSSA]], %[[FOR_COND_LOOPEXIT_LOOPEXIT]] ]
38 ; CHECK-NEXT: [[A_1_LCSSA:%.*]] = phi ptr [ [[A_021]], %[[FOR_BODY]] ], [ [[SCEVGEP1]], %[[FOR_COND_LOOPEXIT_LOOPEXIT]] ]
39 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[T1]], 0
40 ; CHECK-NEXT: br i1 [[TOBOOL]], label %[[FOR_END6]], label %[[FOR_BODY]]
41 ; CHECK: [[FOR_BODY]]:
42 ; CHECK-NEXT: [[T12]] = phi i32 [ [[T1]], %[[FOR_COND_LOOPEXIT]] ], [ [[TMP]], %[[ENTRY]] ]
43 ; CHECK-NEXT: [[R_022]] = phi ptr [ [[R_1_LCSSA]], %[[FOR_COND_LOOPEXIT]] ], [ [[R]], %[[ENTRY]] ]
44 ; CHECK-NEXT: [[A_021]] = phi ptr [ [[A_1_LCSSA]], %[[FOR_COND_LOOPEXIT]] ], [ [[A]], %[[ENTRY]] ]
45 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr @c, align 4
46 ; CHECK-NEXT: [[TOBOOL215:%.*]] = icmp eq i32 [[TMP2]], 0
47 ; CHECK-NEXT: br i1 [[TOBOOL215]], label %[[FOR_COND_LOOPEXIT]], label %[[FOR_BODY3_PREHEADER:.*]]
48 ; CHECK: [[FOR_BODY3_PREHEADER]]:
49 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[TMP2]], -1
50 ; CHECK-NEXT: [[TMP1]] = zext i32 [[TMP0]] to i64
51 ; CHECK-NEXT: [[XTRAITER:%.*]] = and i32 [[TMP2]], 1
52 ; CHECK-NEXT: [[LCMP_MOD_NOT:%.*]] = icmp eq i32 [[XTRAITER]], 0
53 ; CHECK-NEXT: br i1 [[LCMP_MOD_NOT]], label %[[FOR_BODY3_PROL_LOOPEXIT]], label %[[FOR_BODY3_PROL:.*]]
54 ; CHECK: [[FOR_BODY3_PROL]]:
55 ; CHECK-NEXT: [[DEC18_PROL:%.*]] = add nsw i32 [[TMP2]], -1
56 ; CHECK-NEXT: [[TMP3_PROL:%.*]] = load i8, ptr [[A_021]], align 1
57 ; CHECK-NEXT: [[CMP_PROL:%.*]] = icmp eq i8 [[TMP3_PROL]], 0
58 ; CHECK-NEXT: br i1 [[CMP_PROL]], label %[[IF_THEN_PROL:.*]], label %[[FOR_INC_PROL:.*]]
59 ; CHECK: [[IF_THEN_PROL]]:
60 ; CHECK-NEXT: [[ARRAYIDX_PROL:%.*]] = getelementptr inbounds nuw i8, ptr [[R_022]], i64 2
61 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX_PROL]], align 2
62 ; CHECK-NEXT: store i16 0, ptr [[R_022]], align 2
63 ; CHECK-NEXT: [[ARRAYIDX5_PROL:%.*]] = getelementptr inbounds nuw i8, ptr [[R_022]], i64 4
64 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX5_PROL]], align 2
65 ; CHECK-NEXT: br label %[[FOR_INC_PROL]]
66 ; CHECK: [[FOR_INC_PROL]]:
67 ; CHECK-NEXT: [[INCDEC_PTR_PROL:%.*]] = getelementptr inbounds nuw i8, ptr [[A_021]], i64 1
68 ; CHECK-NEXT: [[ADD_PTR_PROL:%.*]] = getelementptr inbounds nuw i8, ptr [[R_022]], i64 6
69 ; CHECK-NEXT: br label %[[FOR_BODY3_PROL_LOOPEXIT]]
70 ; CHECK: [[FOR_BODY3_PROL_LOOPEXIT]]:
71 ; CHECK-NEXT: [[ADD_PTR_LCSSA_UNR]] = phi ptr [ poison, %[[FOR_BODY3_PREHEADER]] ], [ [[ADD_PTR_PROL]], %[[FOR_INC_PROL]] ]
72 ; CHECK-NEXT: [[DEC18_IN_UNR:%.*]] = phi i32 [ [[TMP2]], %[[FOR_BODY3_PREHEADER]] ], [ [[DEC18_PROL]], %[[FOR_INC_PROL]] ]
73 ; CHECK-NEXT: [[R_117_UNR:%.*]] = phi ptr [ [[R_022]], %[[FOR_BODY3_PREHEADER]] ], [ [[ADD_PTR_PROL]], %[[FOR_INC_PROL]] ]
74 ; CHECK-NEXT: [[A_116_UNR:%.*]] = phi ptr [ [[A_021]], %[[FOR_BODY3_PREHEADER]] ], [ [[INCDEC_PTR_PROL]], %[[FOR_INC_PROL]] ]
75 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP0]], 0
76 ; CHECK-NEXT: br i1 [[TMP4]], label %[[FOR_COND_LOOPEXIT_LOOPEXIT]], label %[[FOR_BODY3:.*]]
77 ; CHECK: [[FOR_BODY3]]:
78 ; CHECK-NEXT: [[DEC18_IN:%.*]] = phi i32 [ [[DEC18_1:%.*]], %[[FOR_INC_1]] ], [ [[DEC18_IN_UNR]], %[[FOR_BODY3_PROL_LOOPEXIT]] ]
79 ; CHECK-NEXT: [[R_117:%.*]] = phi ptr [ [[ADD_PTR_1]], %[[FOR_INC_1]] ], [ [[R_117_UNR]], %[[FOR_BODY3_PROL_LOOPEXIT]] ]
80 ; CHECK-NEXT: [[A_116:%.*]] = phi ptr [ [[INCDEC_PTR_1:%.*]], %[[FOR_INC_1]] ], [ [[A_116_UNR]], %[[FOR_BODY3_PROL_LOOPEXIT]] ]
81 ; CHECK-NEXT: [[TMP3:%.*]] = load i8, ptr [[A_116]], align 1
82 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[TMP3]], 0
83 ; CHECK-NEXT: br i1 [[CMP]], label %[[IF_THEN:.*]], label %[[FOR_INC:.*]]
85 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 2
86 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX]], align 2
87 ; CHECK-NEXT: store i16 0, ptr [[R_117]], align 2
88 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 4
89 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX5]], align 2
90 ; CHECK-NEXT: br label %[[FOR_INC]]
92 ; CHECK-NEXT: [[INCDEC_PTR:%.*]] = getelementptr inbounds nuw i8, ptr [[A_116]], i64 1
93 ; CHECK-NEXT: [[DEC18_1]] = add nsw i32 [[DEC18_IN]], -2
94 ; CHECK-NEXT: [[TMP3_1:%.*]] = load i8, ptr [[INCDEC_PTR]], align 1
95 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp eq i8 [[TMP3_1]], 0
96 ; CHECK-NEXT: br i1 [[CMP_1]], label %[[IF_THEN_1:.*]], label %[[FOR_INC_1]]
97 ; CHECK: [[IF_THEN_1]]:
98 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 6
99 ; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 8
100 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX_1]], align 2
101 ; CHECK-NEXT: store i16 0, ptr [[ADD_PTR]], align 2
102 ; CHECK-NEXT: [[ARRAYIDX5_1:%.*]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 10
103 ; CHECK-NEXT: store i16 0, ptr [[ARRAYIDX5_1]], align 2
104 ; CHECK-NEXT: br label %[[FOR_INC_1]]
105 ; CHECK: [[FOR_INC_1]]:
106 ; CHECK-NEXT: [[INCDEC_PTR_1]] = getelementptr inbounds nuw i8, ptr [[A_116]], i64 2
107 ; CHECK-NEXT: [[ADD_PTR_1]] = getelementptr inbounds nuw i8, ptr [[R_117]], i64 12
108 ; CHECK-NEXT: [[TOBOOL2_1:%.*]] = icmp eq i32 [[DEC18_1]], 0
109 ; CHECK-NEXT: br i1 [[TOBOOL2_1]], label %[[FOR_COND_LOOPEXIT_LOOPEXIT]], label %[[FOR_BODY3]], !llvm.loop [[LOOP0:![0-9]+]]
110 ; CHECK: [[FOR_END6]]:
111 ; CHECK-NEXT: ret void
114 %t = load i32, ptr @b, align 4
115 %tobool20 = icmp eq i32 %t, 0
116 br i1 %tobool20, label %for.end6, label %for.body.lr.ph
118 for.body.lr.ph: ; preds = %entry
121 for.cond1.for.cond.loopexit_crit_edge: ; preds = %for.inc
122 %add.ptr.lcssa = phi ptr [ %add.ptr, %for.inc ]
123 %incdec.ptr.lcssa = phi ptr [ %incdec.ptr, %for.inc ]
124 br label %for.cond.loopexit
126 for.cond.loopexit: ; preds = %for.body, %for.cond1.for.cond.loopexit_crit_edge
127 %r.1.lcssa = phi ptr [ %add.ptr.lcssa, %for.cond1.for.cond.loopexit_crit_edge ], [ %r.022, %for.body ]
128 %a.1.lcssa = phi ptr [ %incdec.ptr.lcssa, %for.cond1.for.cond.loopexit_crit_edge ], [ %a.021, %for.body ]
129 %t1 = load i32, ptr @b, align 4
130 %tobool = icmp eq i32 %t1, 0
131 br i1 %tobool, label %for.cond.for.end6_crit_edge, label %for.body
133 for.body: ; preds = %for.cond.loopexit, %for.body.lr.ph
134 %r.022 = phi ptr [ %r, %for.body.lr.ph ], [ %r.1.lcssa, %for.cond.loopexit ]
135 %a.021 = phi ptr [ %a, %for.body.lr.ph ], [ %a.1.lcssa, %for.cond.loopexit ]
136 %t2 = load i32, ptr @c, align 4
137 %tobool215 = icmp eq i32 %t2, 0
138 br i1 %tobool215, label %for.cond.loopexit, label %for.body3.lr.ph
140 for.body3.lr.ph: ; preds = %for.body
143 for.body3: ; preds = %for.inc, %for.body3.lr.ph
144 %dec18.in = phi i32 [ %t2, %for.body3.lr.ph ], [ %dec18, %for.inc ]
145 %r.117 = phi ptr [ %r.022, %for.body3.lr.ph ], [ %add.ptr, %for.inc ]
146 %a.116 = phi ptr [ %a.021, %for.body3.lr.ph ], [ %incdec.ptr, %for.inc ]
147 %dec18 = add nsw i32 %dec18.in, -1
148 %t3 = load i8, ptr %a.116, align 1
149 %cmp = icmp eq i8 %t3, 0
150 br i1 %cmp, label %if.then, label %for.inc
152 if.then: ; preds = %for.body3
153 %arrayidx = getelementptr inbounds i16, ptr %r.117, i64 1
154 store i16 0, ptr %arrayidx, align 2
155 store i16 0, ptr %r.117, align 2
156 %arrayidx5 = getelementptr inbounds i16, ptr %r.117, i64 2
157 store i16 0, ptr %arrayidx5, align 2
160 for.inc: ; preds = %if.then, %for.body3
161 %incdec.ptr = getelementptr inbounds i8, ptr %a.116, i64 1
162 %add.ptr = getelementptr inbounds i16, ptr %r.117, i64 3
163 %tobool2 = icmp eq i32 %dec18, 0
164 br i1 %tobool2, label %for.cond1.for.cond.loopexit_crit_edge, label %for.body3, !llvm.loop !0
166 for.cond.for.end6_crit_edge: ; preds = %for.cond.loopexit
169 for.end6: ; preds = %for.cond.for.end6_crit_edge, %entry
174 !1 = !{!"llvm.loop.unroll.count", i32 2}
176 ; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]]}
177 ; CHECK: [[META1]] = !{!"llvm.loop.unroll.disable"}