1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -mtriple=x86_64-unknown -mattr=+avx -slp-vectorizer | FileCheck %s
4 ;void phiUsingLoads(int *restrict A, int *restrict B) {
5 ; int tmp0, tmp1, tmp2, tmp3;
6 ; for (int i = 0; i < 100; i++) {
12 ; } else if (A[25] == 0) {
17 ; } else if (A[50] == 0) {
22 ; } else if (A[75] == 0) {
36 ; Function Attrs: norecurse nounwind uwtable
37 define void @phiUsingLoads(i32* noalias nocapture readonly %A, i32* noalias nocapture %B) local_unnamed_addr #0 {
38 ; CHECK-LABEL: @phiUsingLoads(
40 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[A:%.*]], align 4
41 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[TMP0]], 0
42 ; CHECK-NEXT: [[ARRAYIDX12:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 25
43 ; CHECK-NEXT: [[ARRAYIDX28:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 50
44 ; CHECK-NEXT: [[ARRAYIDX44:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 75
45 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
46 ; CHECK: for.cond.cleanup:
47 ; CHECK-NEXT: [[ARRAYIDX64:%.*]] = getelementptr inbounds i32, i32* [[B:%.*]], i64 1
48 ; CHECK-NEXT: [[ARRAYIDX65:%.*]] = getelementptr inbounds i32, i32* [[B]], i64 2
49 ; CHECK-NEXT: [[ARRAYIDX66:%.*]] = getelementptr inbounds i32, i32* [[B]], i64 3
50 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[B]] to <4 x i32>*
51 ; CHECK-NEXT: store <4 x i32> [[TMP27:%.*]], <4 x i32>* [[TMP1]], align 4
52 ; CHECK-NEXT: ret void
54 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ]
55 ; CHECK-NEXT: [[TMP2:%.*]] = phi <4 x i32> [ undef, [[ENTRY]] ], [ [[TMP27]], [[FOR_INC]] ]
56 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
58 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
59 ; CHECK-NEXT: [[TMP3:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
60 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP3]]
61 ; CHECK-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 2
62 ; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP4]]
63 ; CHECK-NEXT: [[TMP5:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 3
64 ; CHECK-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP5]]
65 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast i32* [[ARRAYIDX2]] to <4 x i32>*
66 ; CHECK-NEXT: [[TMP7:%.*]] = load <4 x i32>, <4 x i32>* [[TMP6]], align 4
67 ; CHECK-NEXT: br label [[FOR_INC]]
69 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[ARRAYIDX12]], align 4
70 ; CHECK-NEXT: [[CMP13:%.*]] = icmp eq i32 [[TMP8]], 0
71 ; CHECK-NEXT: br i1 [[CMP13]], label [[IF_THEN14:%.*]], label [[IF_ELSE27:%.*]]
73 ; CHECK-NEXT: [[ARRAYIDX17:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
74 ; CHECK-NEXT: [[TMP9:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
75 ; CHECK-NEXT: [[ARRAYIDX20:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP9]]
76 ; CHECK-NEXT: [[TMP10:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 2
77 ; CHECK-NEXT: [[ARRAYIDX23:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP10]]
78 ; CHECK-NEXT: [[TMP11:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 3
79 ; CHECK-NEXT: [[ARRAYIDX26:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP11]]
80 ; CHECK-NEXT: [[TMP12:%.*]] = bitcast i32* [[ARRAYIDX17]] to <4 x i32>*
81 ; CHECK-NEXT: [[TMP13:%.*]] = load <4 x i32>, <4 x i32>* [[TMP12]], align 4
82 ; CHECK-NEXT: br label [[FOR_INC]]
84 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, i32* [[ARRAYIDX28]], align 4
85 ; CHECK-NEXT: [[CMP29:%.*]] = icmp eq i32 [[TMP14]], 0
86 ; CHECK-NEXT: br i1 [[CMP29]], label [[IF_THEN30:%.*]], label [[IF_ELSE43:%.*]]
88 ; CHECK-NEXT: [[ARRAYIDX33:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
89 ; CHECK-NEXT: [[TMP15:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
90 ; CHECK-NEXT: [[ARRAYIDX36:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP15]]
91 ; CHECK-NEXT: [[TMP16:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 2
92 ; CHECK-NEXT: [[ARRAYIDX39:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP16]]
93 ; CHECK-NEXT: [[TMP17:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 3
94 ; CHECK-NEXT: [[ARRAYIDX42:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP17]]
95 ; CHECK-NEXT: [[TMP18:%.*]] = bitcast i32* [[ARRAYIDX33]] to <4 x i32>*
96 ; CHECK-NEXT: [[TMP19:%.*]] = load <4 x i32>, <4 x i32>* [[TMP18]], align 4
97 ; CHECK-NEXT: br label [[FOR_INC]]
99 ; CHECK-NEXT: [[TMP20:%.*]] = load i32, i32* [[ARRAYIDX44]], align 4
100 ; CHECK-NEXT: [[CMP45:%.*]] = icmp eq i32 [[TMP20]], 0
101 ; CHECK-NEXT: br i1 [[CMP45]], label [[IF_THEN46:%.*]], label [[FOR_INC]]
103 ; CHECK-NEXT: [[ARRAYIDX49:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[INDVARS_IV]]
104 ; CHECK-NEXT: [[TMP21:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
105 ; CHECK-NEXT: [[ARRAYIDX52:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP21]]
106 ; CHECK-NEXT: [[TMP22:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 3
107 ; CHECK-NEXT: [[ARRAYIDX55:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP22]]
108 ; CHECK-NEXT: [[TMP23:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 2
109 ; CHECK-NEXT: [[ARRAYIDX58:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP23]]
110 ; CHECK-NEXT: [[TMP24:%.*]] = bitcast i32* [[ARRAYIDX49]] to <4 x i32>*
111 ; CHECK-NEXT: [[TMP25:%.*]] = load <4 x i32>, <4 x i32>* [[TMP24]], align 4
112 ; CHECK-NEXT: [[TMP26:%.*]] = shufflevector <4 x i32> [[TMP25]], <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 3, i32 2>
113 ; CHECK-NEXT: br label [[FOR_INC]]
115 ; CHECK-NEXT: [[TMP27]] = phi <4 x i32> [ [[TMP7]], [[IF_THEN]] ], [ [[TMP13]], [[IF_THEN14]] ], [ [[TMP19]], [[IF_THEN30]] ], [ [[TMP26]], [[IF_THEN46]] ], [ [[TMP2]], [[IF_ELSE43]] ]
116 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
117 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 100
118 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
121 %0 = load i32, i32* %A, align 4
122 %cmp1 = icmp eq i32 %0, 0
123 %arrayidx12 = getelementptr inbounds i32, i32* %A, i64 25
124 %arrayidx28 = getelementptr inbounds i32, i32* %A, i64 50
125 %arrayidx44 = getelementptr inbounds i32, i32* %A, i64 75
128 for.cond.cleanup: ; preds = %for.inc
129 store i32 %tmp0.1, i32* %B, align 4
130 %arrayidx64 = getelementptr inbounds i32, i32* %B, i64 1
131 store i32 %tmp1.1, i32* %arrayidx64, align 4
132 %arrayidx65 = getelementptr inbounds i32, i32* %B, i64 2
133 store i32 %tmp2.1, i32* %arrayidx65, align 4
134 %arrayidx66 = getelementptr inbounds i32, i32* %B, i64 3
135 store i32 %tmp3.1, i32* %arrayidx66, align 4
138 for.body: ; preds = %for.inc, %entry
139 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
140 %tmp3.0111 = phi i32 [ undef, %entry ], [ %tmp3.1, %for.inc ]
141 %tmp2.0110 = phi i32 [ undef, %entry ], [ %tmp2.1, %for.inc ]
142 %tmp1.0109 = phi i32 [ undef, %entry ], [ %tmp1.1, %for.inc ]
143 %tmp0.0108 = phi i32 [ undef, %entry ], [ %tmp0.1, %for.inc ]
144 br i1 %cmp1, label %if.then, label %if.else
146 if.then: ; preds = %for.body
147 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
148 %1 = load i32, i32* %arrayidx2, align 4
149 %2 = add nuw nsw i64 %indvars.iv, 1
150 %arrayidx5 = getelementptr inbounds i32, i32* %A, i64 %2
151 %3 = load i32, i32* %arrayidx5, align 4
152 %4 = add nuw nsw i64 %indvars.iv, 2
153 %arrayidx8 = getelementptr inbounds i32, i32* %A, i64 %4
154 %5 = load i32, i32* %arrayidx8, align 4
155 %6 = add nuw nsw i64 %indvars.iv, 3
156 %arrayidx11 = getelementptr inbounds i32, i32* %A, i64 %6
157 %7 = load i32, i32* %arrayidx11, align 4
160 if.else: ; preds = %for.body
161 %8 = load i32, i32* %arrayidx12, align 4
162 %cmp13 = icmp eq i32 %8, 0
163 br i1 %cmp13, label %if.then14, label %if.else27
165 if.then14: ; preds = %if.else
166 %arrayidx17 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
167 %9 = load i32, i32* %arrayidx17, align 4
168 %10 = add nuw nsw i64 %indvars.iv, 1
169 %arrayidx20 = getelementptr inbounds i32, i32* %A, i64 %10
170 %11 = load i32, i32* %arrayidx20, align 4
171 %12 = add nuw nsw i64 %indvars.iv, 2
172 %arrayidx23 = getelementptr inbounds i32, i32* %A, i64 %12
173 %13 = load i32, i32* %arrayidx23, align 4
174 %14 = add nuw nsw i64 %indvars.iv, 3
175 %arrayidx26 = getelementptr inbounds i32, i32* %A, i64 %14
176 %15 = load i32, i32* %arrayidx26, align 4
179 if.else27: ; preds = %if.else
180 %16 = load i32, i32* %arrayidx28, align 4
181 %cmp29 = icmp eq i32 %16, 0
182 br i1 %cmp29, label %if.then30, label %if.else43
184 if.then30: ; preds = %if.else27
185 %arrayidx33 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
186 %17 = load i32, i32* %arrayidx33, align 4
187 %18 = add nuw nsw i64 %indvars.iv, 1
188 %arrayidx36 = getelementptr inbounds i32, i32* %A, i64 %18
189 %19 = load i32, i32* %arrayidx36, align 4
190 %20 = add nuw nsw i64 %indvars.iv, 2
191 %arrayidx39 = getelementptr inbounds i32, i32* %A, i64 %20
192 %21 = load i32, i32* %arrayidx39, align 4
193 %22 = add nuw nsw i64 %indvars.iv, 3
194 %arrayidx42 = getelementptr inbounds i32, i32* %A, i64 %22
195 %23 = load i32, i32* %arrayidx42, align 4
198 if.else43: ; preds = %if.else27
199 %24 = load i32, i32* %arrayidx44, align 4
200 %cmp45 = icmp eq i32 %24, 0
201 br i1 %cmp45, label %if.then46, label %for.inc
203 if.then46: ; preds = %if.else43
204 %arrayidx49 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
205 %25 = load i32, i32* %arrayidx49, align 4
206 %26 = add nuw nsw i64 %indvars.iv, 1
207 %arrayidx52 = getelementptr inbounds i32, i32* %A, i64 %26
208 %27 = load i32, i32* %arrayidx52, align 4
209 %28 = add nuw nsw i64 %indvars.iv, 3
210 %arrayidx55 = getelementptr inbounds i32, i32* %A, i64 %28
211 %29 = load i32, i32* %arrayidx55, align 4
212 %30 = add nuw nsw i64 %indvars.iv, 2
213 %arrayidx58 = getelementptr inbounds i32, i32* %A, i64 %30
214 %31 = load i32, i32* %arrayidx58, align 4
217 for.inc: ; preds = %if.then, %if.then30, %if.else43, %if.then46, %if.then14
218 %tmp0.1 = phi i32 [ %1, %if.then ], [ %9, %if.then14 ], [ %17, %if.then30 ], [ %25, %if.then46 ], [ %tmp0.0108, %if.else43 ]
219 %tmp1.1 = phi i32 [ %3, %if.then ], [ %11, %if.then14 ], [ %19, %if.then30 ], [ %27, %if.then46 ], [ %tmp1.0109, %if.else43 ]
220 %tmp2.1 = phi i32 [ %5, %if.then ], [ %13, %if.then14 ], [ %21, %if.then30 ], [ %29, %if.then46 ], [ %tmp2.0110, %if.else43 ]
221 %tmp3.1 = phi i32 [ %7, %if.then ], [ %15, %if.then14 ], [ %23, %if.then30 ], [ %31, %if.then46 ], [ %tmp3.0111, %if.else43 ]
222 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
223 %exitcond = icmp eq i64 %indvars.iv.next, 100
224 br i1 %exitcond, label %for.cond.cleanup, label %for.body