1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5 target datalayout = "n32:64"
7 define void @MainKernel(i32 %iNumSteps, i32 %tid, i32 %base) {
8 ; CHECK-LABEL: @MainKernel(
9 ; CHECK-NEXT: [[CALLA:%.*]] = alloca [258 x float], align 4
10 ; CHECK-NEXT: [[CALLB:%.*]] = alloca [258 x float], align 4
11 ; CHECK-NEXT: [[CONV_I:%.*]] = uitofp i32 [[INUMSTEPS:%.*]] to float
12 ; CHECK-NEXT: [[CONV_I12:%.*]] = zext i32 [[TID:%.*]] to i64
13 ; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLA]], i64 0, i64 [[CONV_I12]]
14 ; CHECK-NEXT: store float [[CONV_I]], float* [[ARRAYIDX3]], align 4
15 ; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLB]], i64 0, i64 [[CONV_I12]]
16 ; CHECK-NEXT: store float [[CONV_I]], float* [[ARRAYIDX6]], align 4
17 ; CHECK-NEXT: [[CMP7:%.*]] = icmp eq i32 [[TID]], 0
18 ; CHECK-NEXT: br i1 [[CMP7]], label [[DOTBB1:%.*]], label [[DOTBB2:%.*]]
20 ; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLA]], i64 0, i64 256
21 ; CHECK-NEXT: store float [[CONV_I]], float* [[ARRAYIDX10]], align 4
22 ; CHECK-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLB]], i64 0, i64 256
23 ; CHECK-NEXT: store float 0.000000e+00, float* [[ARRAYIDX11]], align 4
24 ; CHECK-NEXT: br label [[DOTBB2]]
26 ; CHECK-NEXT: [[CMP135:%.*]] = icmp sgt i32 [[INUMSTEPS]], 0
27 ; CHECK-NEXT: br i1 [[CMP135]], label [[DOTBB3:%.*]], label [[DOTBB8:%.*]]
29 ; CHECK-NEXT: [[TMP1:%.*]] = phi float [ [[TMP10:%.*]], [[DOTBB12:%.*]] ], [ [[CONV_I]], [[DOTBB2]] ]
30 ; CHECK-NEXT: [[TMP2:%.*]] = phi float [ [[TMP11:%.*]], [[DOTBB12]] ], [ [[CONV_I]], [[DOTBB2]] ]
31 ; CHECK-NEXT: [[I12_06:%.*]] = phi i32 [ [[SUB:%.*]], [[DOTBB12]] ], [ [[INUMSTEPS]], [[DOTBB2]] ]
32 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt i32 [[I12_06]], [[BASE:%.*]]
33 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[I12_06]], 1
34 ; CHECK-NEXT: [[CONV_I9:%.*]] = sext i32 [[ADD]] to i64
35 ; CHECK-NEXT: [[ARRAYIDX20:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLA]], i64 0, i64 [[CONV_I9]]
36 ; CHECK-NEXT: [[ARRAYIDX24:%.*]] = getelementptr inbounds [258 x float], [258 x float]* [[CALLB]], i64 0, i64 [[CONV_I9]]
37 ; CHECK-NEXT: [[CMP40:%.*]] = icmp ult i32 [[I12_06]], [[BASE]]
38 ; CHECK-NEXT: br i1 [[TMP3]], label [[DOTBB4:%.*]], label [[DOTBB5:%.*]]
40 ; CHECK-NEXT: [[TMP4:%.*]] = load float, float* [[ARRAYIDX20]], align 4
41 ; CHECK-NEXT: [[TMP5:%.*]] = load float, float* [[ARRAYIDX24]], align 4
42 ; CHECK-NEXT: [[ADD33:%.*]] = fadd float [[TMP5]], [[TMP4]]
43 ; CHECK-NEXT: [[ADD33_1:%.*]] = fadd float [[ADD33]], [[TMP1]]
44 ; CHECK-NEXT: [[ADD33_2:%.*]] = fadd float [[ADD33_1]], [[TMP2]]
45 ; CHECK-NEXT: br label [[DOTBB5]]
47 ; CHECK-NEXT: [[TMP6:%.*]] = phi float [ [[ADD33_1]], [[DOTBB4]] ], [ [[TMP1]], [[DOTBB3]] ]
48 ; CHECK-NEXT: [[TMP7:%.*]] = phi float [ [[ADD33_2]], [[DOTBB4]] ], [ [[TMP2]], [[DOTBB3]] ]
49 ; CHECK-NEXT: br i1 [[CMP40]], label [[DOTBB6:%.*]], label [[DOTBB7:%.*]]
51 ; CHECK-NEXT: store float [[TMP7]], float* [[ARRAYIDX3]], align 4
52 ; CHECK-NEXT: store float [[TMP6]], float* [[ARRAYIDX6]], align 4
53 ; CHECK-NEXT: br label [[DOTBB7]]
55 ; CHECK-NEXT: br i1 [[TMP3]], label [[DOTBB9:%.*]], label [[DOTBB10:%.*]]
57 ; CHECK-NEXT: ret void
59 ; CHECK-NEXT: [[TMP8:%.*]] = load float, float* [[ARRAYIDX20]], align 4
60 ; CHECK-NEXT: [[TMP9:%.*]] = load float, float* [[ARRAYIDX24]], align 4
61 ; CHECK-NEXT: [[ADD33_112:%.*]] = fadd float [[TMP9]], [[TMP8]]
62 ; CHECK-NEXT: [[ADD33_1_1:%.*]] = fadd float [[ADD33_112]], [[TMP6]]
63 ; CHECK-NEXT: [[ADD33_2_1:%.*]] = fadd float [[ADD33_1_1]], [[TMP7]]
64 ; CHECK-NEXT: br label [[DOTBB10]]
66 ; CHECK-NEXT: [[TMP10]] = phi float [ [[ADD33_1_1]], [[DOTBB9]] ], [ [[TMP6]], [[DOTBB7]] ]
67 ; CHECK-NEXT: [[TMP11]] = phi float [ [[ADD33_2_1]], [[DOTBB9]] ], [ [[TMP7]], [[DOTBB7]] ]
68 ; CHECK-NEXT: br i1 [[CMP40]], label [[DOTBB11:%.*]], label [[DOTBB12]]
70 ; CHECK-NEXT: store float [[TMP11]], float* [[ARRAYIDX3]], align 4
71 ; CHECK-NEXT: store float [[TMP10]], float* [[ARRAYIDX6]], align 4
72 ; CHECK-NEXT: br label [[DOTBB12]]
74 ; CHECK-NEXT: [[SUB]] = add i32 [[I12_06]], -4
75 ; CHECK-NEXT: [[CMP13:%.*]] = icmp sgt i32 [[SUB]], 0
76 ; CHECK-NEXT: br i1 [[CMP13]], label [[DOTBB3]], label [[DOTBB8]]
78 %callA = alloca [258 x float], align 4
79 %callB = alloca [258 x float], align 4
80 %conv.i = uitofp i32 %iNumSteps to float
81 %1 = bitcast float %conv.i to i32
82 %conv.i12 = zext i32 %tid to i64
83 %arrayidx3 = getelementptr inbounds [258 x float], [258 x float]* %callA, i64 0, i64 %conv.i12
84 %2 = bitcast float* %arrayidx3 to i32*
85 store i32 %1, i32* %2, align 4
86 %arrayidx6 = getelementptr inbounds [258 x float], [258 x float]* %callB, i64 0, i64 %conv.i12
87 %3 = bitcast float* %arrayidx6 to i32*
88 store i32 %1, i32* %3, align 4
89 %cmp7 = icmp eq i32 %tid, 0
90 br i1 %cmp7, label %.bb1, label %.bb2
93 %arrayidx10 = getelementptr inbounds [258 x float], [258 x float]* %callA, i64 0, i64 256
94 store float %conv.i, float* %arrayidx10, align 4
95 %arrayidx11 = getelementptr inbounds [258 x float], [258 x float]* %callB, i64 0, i64 256
96 store float 0.000000e+00, float* %arrayidx11, align 4
100 %cmp135 = icmp sgt i32 %iNumSteps, 0
101 br i1 %cmp135, label %.bb3, label %.bb8
104 %rA.sroa.8.0 = phi i32 [ %rA.sroa.8.2, %.bb12 ], [ %1, %.bb2 ]
105 %rA.sroa.0.0 = phi i32 [ %rA.sroa.0.2, %.bb12 ], [ %1, %.bb2 ]
106 %i12.06 = phi i32 [ %sub, %.bb12 ], [ %iNumSteps, %.bb2 ]
107 %4 = icmp ugt i32 %i12.06, %base
108 %add = add i32 %i12.06, 1
109 %conv.i9 = sext i32 %add to i64
110 %arrayidx20 = getelementptr inbounds [258 x float], [258 x float]* %callA, i64 0, i64 %conv.i9
111 %5 = bitcast float* %arrayidx20 to i32*
112 %arrayidx24 = getelementptr inbounds [258 x float], [258 x float]* %callB, i64 0, i64 %conv.i9
113 %6 = bitcast float* %arrayidx24 to i32*
114 %cmp40 = icmp ult i32 %i12.06, %base
115 br i1 %4, label %.bb4, label %.bb5
118 %7 = load i32, i32* %5, align 4
119 %8 = load i32, i32* %6, align 4
120 %9 = bitcast i32 %8 to float
121 %10 = bitcast i32 %7 to float
122 %add33 = fadd float %9, %10
123 %11 = bitcast i32 %rA.sroa.8.0 to float
124 %add33.1 = fadd float %add33, %11
125 %12 = bitcast float %add33.1 to i32
126 %13 = bitcast i32 %rA.sroa.0.0 to float
127 %add33.2 = fadd float %add33.1, %13
128 %14 = bitcast float %add33.2 to i32
132 %rA.sroa.8.1 = phi i32 [ %12, %.bb4 ], [ %rA.sroa.8.0, %.bb3 ]
133 %rA.sroa.0.1 = phi i32 [ %14, %.bb4 ], [ %rA.sroa.0.0, %.bb3 ]
134 br i1 %cmp40, label %.bb6, label %.bb7
137 store i32 %rA.sroa.0.1, i32* %2, align 4
138 store i32 %rA.sroa.8.1, i32* %3, align 4
142 br i1 %4, label %.bb9, label %.bb10
148 %15 = load i32, i32* %5, align 4
149 %16 = load i32, i32* %6, align 4
150 %17 = bitcast i32 %16 to float
151 %18 = bitcast i32 %15 to float
152 %add33.112 = fadd float %17, %18
153 %19 = bitcast i32 %rA.sroa.8.1 to float
154 %add33.1.1 = fadd float %add33.112, %19
155 %20 = bitcast float %add33.1.1 to i32
156 %21 = bitcast i32 %rA.sroa.0.1 to float
157 %add33.2.1 = fadd float %add33.1.1, %21
158 %22 = bitcast float %add33.2.1 to i32
162 %rA.sroa.8.2 = phi i32 [ %20, %.bb9 ], [ %rA.sroa.8.1, %.bb7 ]
163 %rA.sroa.0.2 = phi i32 [ %22, %.bb9 ], [ %rA.sroa.0.1, %.bb7 ]
164 br i1 %cmp40, label %.bb11, label %.bb12
167 store i32 %rA.sroa.0.2, i32* %2, align 4
168 store i32 %rA.sroa.8.2, i32* %3, align 4
172 %sub = add i32 %i12.06, -4
173 %cmp13 = icmp sgt i32 %sub, 0
174 br i1 %cmp13, label %.bb3, label %.bb8
177 declare i32 @get_i32()
181 define i37 @zext_from_legal_to_illegal_type(i32 %x) {
182 ; CHECK-LABEL: @zext_from_legal_to_illegal_type(
184 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 42
185 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
187 ; CHECK-NEXT: [[Y:%.*]] = call i32 @get_i32()
188 ; CHECK-NEXT: br label [[EXIT:%.*]]
190 ; CHECK-NEXT: call void @bar()
191 ; CHECK-NEXT: br label [[EXIT]]
193 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[Y]], [[T]] ], [ 3, [[F]] ]
194 ; CHECK-NEXT: [[R:%.*]] = zext i32 [[P]] to i37
195 ; CHECK-NEXT: ret i37 [[R]]
198 %cmp = icmp eq i32 %x, 42
199 br i1 %cmp, label %t, label %f
202 %y = call i32 @get_i32()
210 %p = phi i32 [ %y, %t ], [ 3, %f ]
211 %r = zext i32 %p to i37
215 define i37 @zext_from_illegal_to_illegal_type(i32 %x) {
216 ; CHECK-LABEL: @zext_from_illegal_to_illegal_type(
218 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 42
219 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
221 ; CHECK-NEXT: [[Y:%.*]] = call i3 @get_i3()
222 ; CHECK-NEXT: br label [[EXIT:%.*]]
224 ; CHECK-NEXT: call void @bar()
225 ; CHECK-NEXT: br label [[EXIT]]
227 ; CHECK-NEXT: [[P:%.*]] = phi i3 [ [[Y]], [[T]] ], [ 3, [[F]] ]
228 ; CHECK-NEXT: [[R:%.*]] = zext i3 [[P]] to i37
229 ; CHECK-NEXT: ret i37 [[R]]
232 %cmp = icmp eq i32 %x, 42
233 br i1 %cmp, label %t, label %f
236 %y = call i3 @get_i3()
244 %p = phi i3 [ %y, %t ], [ 3, %f ]
245 %r = zext i3 %p to i37
249 define i64 @zext_from_legal_to_legal_type(i32 %x) {
250 ; CHECK-LABEL: @zext_from_legal_to_legal_type(
252 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 42
253 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
255 ; CHECK-NEXT: [[Y:%.*]] = call i32 @get_i32()
256 ; CHECK-NEXT: [[PHITMP:%.*]] = zext i32 [[Y]] to i64
257 ; CHECK-NEXT: br label [[EXIT:%.*]]
259 ; CHECK-NEXT: call void @bar()
260 ; CHECK-NEXT: br label [[EXIT]]
262 ; CHECK-NEXT: [[P:%.*]] = phi i64 [ [[PHITMP]], [[T]] ], [ 3, [[F]] ]
263 ; CHECK-NEXT: ret i64 [[P]]
266 %cmp = icmp eq i32 %x, 42
267 br i1 %cmp, label %t, label %f
270 %y = call i32 @get_i32()
278 %p = phi i32 [ %y, %t ], [ 3, %f ]
279 %r = zext i32 %p to i64
283 define i64 @zext_from_illegal_to_legal_type(i32 %x) {
284 ; CHECK-LABEL: @zext_from_illegal_to_legal_type(
286 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 42
287 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
289 ; CHECK-NEXT: [[Y:%.*]] = call i3 @get_i3()
290 ; CHECK-NEXT: [[PHITMP:%.*]] = zext i3 [[Y]] to i64
291 ; CHECK-NEXT: br label [[EXIT:%.*]]
293 ; CHECK-NEXT: call void @bar()
294 ; CHECK-NEXT: br label [[EXIT]]
296 ; CHECK-NEXT: [[P:%.*]] = phi i64 [ [[PHITMP]], [[T]] ], [ 3, [[F]] ]
297 ; CHECK-NEXT: ret i64 [[P]]
300 %cmp = icmp eq i32 %x, 42
301 br i1 %cmp, label %t, label %f
304 %y = call i3 @get_i3()
312 %p = phi i3 [ %y, %t ], [ 3, %f ]
313 %r = zext i3 %p to i64