Skip to content

Commit a489bf4

Browse files
committed
[InstCombine] Add tests for scalarizing of blended vector inserts; NFC
1 parent f581149 commit a489bf4

File tree

1 file changed

+266
-0
lines changed

1 file changed

+266
-0
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes='instcombine' -S %s | FileCheck %s
3+
4+
declare void @use.v2.float(<2 x float>)
5+
define <2 x float> @replace_through_casts(i16 %inp) {
6+
; CHECK-LABEL: @replace_through_casts(
7+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
8+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[INP]], i64 0
9+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
10+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
11+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
12+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V]], <2 x float> [[SI_V]], <2 x i32> <i32 0, i32 3>
13+
; CHECK-NEXT: ret <2 x float> [[R]]
14+
;
15+
%add = add nsw i16 %inp, -10
16+
%v0 = insertelement <2 x i16> poison, i16 %inp, i64 0
17+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
18+
%ui_v = uitofp <2 x i16> %v to <2 x float>
19+
%si_v = sitofp <2 x i16> %v to <2 x float>
20+
%r = shufflevector <2 x float> %ui_v, <2 x float> %si_v, <2 x i32> <i32 0, i32 3>
21+
ret <2 x float> %r
22+
}
23+
24+
define <2 x float> @replace_through_casts_and_binop(i16 %inp) {
25+
; CHECK-LABEL: @replace_through_casts_and_binop(
26+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
27+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i16 [[INP]], 5
28+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[MUL]], i64 0
29+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
30+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
31+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
32+
; CHECK-NEXT: [[UI_V_ADD:%.*]] = fadd <2 x float> [[UI_V]], <float 2.000000e+00, float poison>
33+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V_ADD]], <2 x float> [[SI_V]], <2 x i32> <i32 0, i32 3>
34+
; CHECK-NEXT: ret <2 x float> [[R]]
35+
;
36+
%add = add nsw i16 %inp, -10
37+
%mul = mul nsw i16 %inp, 5
38+
%v0 = insertelement <2 x i16> poison, i16 %mul, i64 0
39+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
40+
%ui_v = uitofp <2 x i16> %v to <2 x float>
41+
%si_v = sitofp <2 x i16> %v to <2 x float>
42+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
43+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v, <2 x i32> <i32 0, i32 3>
44+
ret <2 x float> %r
45+
}
46+
47+
define <2 x float> @replace_through_casts_and_binop_and_unop(i16 %inp) {
48+
; CHECK-LABEL: @replace_through_casts_and_binop_and_unop(
49+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
50+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[ADD]], i64 0
51+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[INP]], i64 1
52+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
53+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
54+
; CHECK-NEXT: [[UI_V_ADD:%.*]] = fadd <2 x float> [[UI_V]], <float 2.000000e+00, float poison>
55+
; CHECK-NEXT: [[SI_V_FNEG:%.*]] = fneg <2 x float> [[SI_V]]
56+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V_ADD]], <2 x float> [[SI_V_FNEG]], <2 x i32> <i32 0, i32 2>
57+
; CHECK-NEXT: ret <2 x float> [[R]]
58+
;
59+
%add = add nsw i16 %inp, -10
60+
%v0 = insertelement <2 x i16> poison, i16 %add, i64 0
61+
%v = insertelement <2 x i16> %v0, i16 %inp, i64 1
62+
%ui_v = uitofp <2 x i16> %v to <2 x float>
63+
%si_v = sitofp <2 x i16> %v to <2 x float>
64+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
65+
%si_v_fneg = fneg <2 x float> %si_v
66+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v_fneg, <2 x i32> <i32 0, i32 2>
67+
ret <2 x float> %r
68+
}
69+
70+
define <2 x float> @replace_through_casts_through_splat(i16 %inp) {
71+
; CHECK-LABEL: @replace_through_casts_through_splat(
72+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
73+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[ADD]], i64 0
74+
; CHECK-NEXT: [[V:%.*]] = shufflevector <2 x i16> [[V0]], <2 x i16> poison, <2 x i32> zeroinitializer
75+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
76+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
77+
; CHECK-NEXT: [[UI_V_ADD:%.*]] = fadd <2 x float> [[UI_V]], <float 2.000000e+00, float poison>
78+
; CHECK-NEXT: [[SI_V_FNEG:%.*]] = fneg <2 x float> [[SI_V]]
79+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V_ADD]], <2 x float> [[SI_V_FNEG]], <2 x i32> <i32 0, i32 3>
80+
; CHECK-NEXT: ret <2 x float> [[R]]
81+
;
82+
%add = add nsw i16 %inp, -10
83+
%v0 = insertelement <2 x i16> poison, i16 %add, i64 0
84+
%v = shufflevector <2 x i16> %v0, <2 x i16> poison, <2 x i32> zeroinitializer
85+
%ui_v = uitofp <2 x i16> %v to <2 x float>
86+
%si_v = sitofp <2 x i16> %v to <2 x float>
87+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
88+
%si_v_fneg = fneg <2 x float> %si_v
89+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v_fneg, <2 x i32> <i32 0, i32 3>
90+
ret <2 x float> %r
91+
}
92+
93+
define <2 x float> @replace_through_casts_through_splat2(i16 %inp, <2 x i16> %any) {
94+
; CHECK-LABEL: @replace_through_casts_through_splat2(
95+
; CHECK-NEXT: ret <2 x float> poison
96+
;
97+
%add = add nsw i16 %inp, -10
98+
%v0 = insertelement <2 x i16> poison, i16 %add, i64 0
99+
%v = shufflevector <2 x i16> %v0, <2 x i16> %any, <2 x i32> <i32 1, i32 1>
100+
%ui_v = uitofp <2 x i16> %v to <2 x float>
101+
%si_v = sitofp <2 x i16> %v to <2 x float>
102+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
103+
%si_v_fneg = fneg <2 x float> %si_v
104+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v_fneg, <2 x i32> <i32 0, i32 3>
105+
ret <2 x float> %r
106+
}
107+
108+
define <2 x float> @replace_through_casts_through_splat_fail(i16 %inp, <2 x i16> %any) {
109+
; CHECK-LABEL: @replace_through_casts_through_splat_fail(
110+
; CHECK-NEXT: [[V:%.*]] = shufflevector <2 x i16> [[V0:%.*]], <2 x i16> poison, <2 x i32> zeroinitializer
111+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
112+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
113+
; CHECK-NEXT: [[UI_V_ADD:%.*]] = fadd <2 x float> [[UI_V]], <float 2.000000e+00, float poison>
114+
; CHECK-NEXT: [[SI_V_FNEG:%.*]] = fneg <2 x float> [[SI_V]]
115+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V_ADD]], <2 x float> [[SI_V_FNEG]], <2 x i32> <i32 0, i32 3>
116+
; CHECK-NEXT: ret <2 x float> [[R]]
117+
;
118+
%add = add nsw i16 %inp, -10
119+
%v0 = insertelement <2 x i16> poison, i16 %add, i64 1
120+
%v = shufflevector <2 x i16> %v0, <2 x i16> %any, <2 x i32> <i32 2, i32 2>
121+
%ui_v = uitofp <2 x i16> %v to <2 x float>
122+
%si_v = sitofp <2 x i16> %v to <2 x float>
123+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
124+
%si_v_fneg = fneg <2 x float> %si_v
125+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v_fneg, <2 x i32> <i32 0, i32 3>
126+
ret <2 x float> %r
127+
}
128+
129+
define <2 x i32> @replace_through_int_casts(i16 %inp, <2 x i16> %dead) {
130+
; CHECK-LABEL: @replace_through_int_casts(
131+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
132+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[INP]], i64 0
133+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
134+
; CHECK-NEXT: [[ZI32_V:%.*]] = zext <2 x i16> [[V]] to <2 x i32>
135+
; CHECK-NEXT: [[SI32_V:%.*]] = sext <2 x i16> [[V]] to <2 x i32>
136+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[ZI32_V]], <2 x i32> [[SI32_V]], <2 x i32> <i32 0, i32 3>
137+
; CHECK-NEXT: ret <2 x i32> [[R]]
138+
;
139+
%add = add nsw i16 %inp, -10
140+
%v0 = insertelement <2 x i16> %dead, i16 %inp, i64 0
141+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
142+
%zi32_v = zext <2 x i16> %v to <2 x i32>
143+
%si32_v = sext <2 x i16> %v to <2 x i32>
144+
%r = shufflevector <2 x i32> %zi32_v, <2 x i32> %si32_v, <2 x i32> <i32 0, i32 3>
145+
ret <2 x i32> %r
146+
}
147+
148+
define <2 x float> @replace_through_int_bitcasts_todo(i16 %inp, <2 x i16> %dead) {
149+
; CHECK-LABEL: @replace_through_int_bitcasts_todo(
150+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
151+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[INP]], i64 0
152+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
153+
; CHECK-NEXT: [[ZI32_V:%.*]] = zext <2 x i16> [[V]] to <2 x i32>
154+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
155+
; CHECK-NEXT: [[BI_V:%.*]] = bitcast <2 x i32> [[ZI32_V]] to <2 x float>
156+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[BI_V]], <2 x float> [[SI_V]], <2 x i32> <i32 0, i32 3>
157+
; CHECK-NEXT: ret <2 x float> [[R]]
158+
;
159+
%add = add nsw i16 %inp, -10
160+
%v0 = insertelement <2 x i16> %dead, i16 %inp, i64 0
161+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
162+
%zi32_v = zext <2 x i16> %v to <2 x i32>
163+
%si_v = sitofp <2 x i16> %v to <2 x float>
164+
%bi_v = bitcast <2 x i32> %zi32_v to <2 x float>
165+
%r = shufflevector <2 x float> %bi_v, <2 x float> %si_v, <2 x i32> <i32 0, i32 3>
166+
ret <2 x float> %r
167+
}
168+
169+
define <2 x float> @replace_through_casts_todo_fail_multiuse(i16 %inp) {
170+
; CHECK-LABEL: @replace_through_casts_todo_fail_multiuse(
171+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
172+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[ADD]], i64 0
173+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[INP]], i64 1
174+
; CHECK-NEXT: [[UI_V:%.*]] = uitofp <2 x i16> [[V]] to <2 x float>
175+
; CHECK-NEXT: [[SI_V:%.*]] = sitofp <2 x i16> [[V]] to <2 x float>
176+
; CHECK-NEXT: [[UI_V_ADD:%.*]] = fadd <2 x float> [[UI_V]], <float 2.000000e+00, float poison>
177+
; CHECK-NEXT: [[SI_V_FNEG:%.*]] = fneg <2 x float> [[SI_V]]
178+
; CHECK-NEXT: call void @use.v2.float(<2 x float> [[UI_V]])
179+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[UI_V_ADD]], <2 x float> [[SI_V_FNEG]], <2 x i32> <i32 0, i32 3>
180+
; CHECK-NEXT: ret <2 x float> [[R]]
181+
;
182+
%add = add nsw i16 %inp, -10
183+
%v0 = insertelement <2 x i16> poison, i16 %add, i64 0
184+
%v = insertelement <2 x i16> %v0, i16 %inp, i64 1
185+
%ui_v = uitofp <2 x i16> %v to <2 x float>
186+
%si_v = sitofp <2 x i16> %v to <2 x float>
187+
%ui_v_add = fadd <2 x float> %ui_v, <float 2.0, float 3.0>
188+
%si_v_fneg = fneg <2 x float> %si_v
189+
call void @use.v2.float(<2 x float> %ui_v)
190+
%r = shufflevector <2 x float> %ui_v_add, <2 x float> %si_v_fneg, <2 x i32> <i32 0, i32 3>
191+
ret <2 x float> %r
192+
}
193+
194+
define <2 x i32> @replace_through_int_casts_ele0_only(i16 %inp, <2 x i16> %dead) {
195+
; CHECK-LABEL: @replace_through_int_casts_ele0_only(
196+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
197+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[INP]], i64 0
198+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
199+
; CHECK-NEXT: [[ZI32_V:%.*]] = zext <2 x i16> [[V]] to <2 x i32>
200+
; CHECK-NEXT: [[SI32_V:%.*]] = sext <2 x i16> [[V]] to <2 x i32>
201+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[ZI32_V]], <2 x i32> [[SI32_V]], <2 x i32> <i32 0, i32 2>
202+
; CHECK-NEXT: ret <2 x i32> [[R]]
203+
;
204+
%add = add nsw i16 %inp, -10
205+
%v0 = insertelement <2 x i16> poison, i16 %inp, i64 0
206+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
207+
%zi32_v = zext <2 x i16> %v to <2 x i32>
208+
%si32_v = sext <2 x i16> %v to <2 x i32>
209+
%r = shufflevector <2 x i32> %zi32_v, <2 x i32> %si32_v, <2 x i32> <i32 0, i32 2>
210+
ret <2 x i32> %r
211+
}
212+
213+
define <2 x i32> @replace_through_int_casts_fail_op0_only(i16 %inp, <2 x i16> %dead) {
214+
; CHECK-LABEL: @replace_through_int_casts_fail_op0_only(
215+
; CHECK-NEXT: [[ADD:%.*]] = add nsw i16 [[INP:%.*]], -10
216+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i16> poison, i16 [[INP]], i64 0
217+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i16> [[V0]], i16 [[ADD]], i64 1
218+
; CHECK-NEXT: [[ZI32_V:%.*]] = zext <2 x i16> [[V]] to <2 x i32>
219+
; CHECK-NEXT: ret <2 x i32> [[ZI32_V]]
220+
;
221+
%add = add nsw i16 %inp, -10
222+
%v0 = insertelement <2 x i16> poison, i16 %inp, i64 0
223+
%v = insertelement <2 x i16> %v0, i16 %add, i64 1
224+
%zi32_v = zext <2 x i16> %v to <2 x i32>
225+
%si32_v = sext <2 x i16> %v to <2 x i32>
226+
%r = shufflevector <2 x i32> %zi32_v, <2 x i32> %si32_v, <2 x i32> <i32 0, i32 1>
227+
ret <2 x i32> %r
228+
}
229+
230+
define <2 x i8> @replace_through_binop_fail_cant_speculate(i8 %inp, <2 x i8> %d, <2 x i8> %any) {
231+
; CHECK-LABEL: @replace_through_binop_fail_cant_speculate(
232+
; CHECK-NEXT: [[ADD:%.*]] = add i8 [[INP:%.*]], 5
233+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i8> poison, i8 [[INP]], i64 0
234+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i8> [[V0]], i8 [[ADD]], i64 1
235+
; CHECK-NEXT: [[DIV0:%.*]] = sdiv <2 x i8> <i8 -128, i8 -128>, [[V]]
236+
; CHECK-NEXT: [[DIV1:%.*]] = xor <2 x i8> [[V]], <i8 123, i8 poison>
237+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i8> [[DIV1]], <2 x i8> [[DIV0]], <2 x i32> <i32 0, i32 3>
238+
; CHECK-NEXT: ret <2 x i8> [[R]]
239+
;
240+
%add = add i8 %inp, 5
241+
%v0 = insertelement <2 x i8> %any, i8 %inp, i64 0
242+
%v = insertelement <2 x i8> %v0, i8 %add, i64 1
243+
%div0 = sdiv <2 x i8> <i8 128, i8 128>, %v
244+
%div1 = xor <2 x i8> %v, <i8 123, i8 12>
245+
%r = shufflevector <2 x i8> %div1, <2 x i8> %div0, <2 x i32> <i32 0, i32 3>
246+
ret <2 x i8> %r
247+
}
248+
249+
define <2 x i8> @replace_through_binop_preserve_flags(i8 %inp, <2 x i8> %d, <2 x i8> %any) {
250+
; CHECK-LABEL: @replace_through_binop_preserve_flags(
251+
; CHECK-NEXT: [[ADD:%.*]] = xor i8 [[INP:%.*]], 5
252+
; CHECK-NEXT: [[V0:%.*]] = insertelement <2 x i8> poison, i8 [[INP]], i64 0
253+
; CHECK-NEXT: [[V:%.*]] = insertelement <2 x i8> [[V0]], i8 [[ADD]], i64 1
254+
; CHECK-NEXT: [[DIV0:%.*]] = add nsw <2 x i8> [[V]], <i8 poison, i8 1>
255+
; CHECK-NEXT: [[DIV1:%.*]] = xor <2 x i8> [[V]], <i8 123, i8 poison>
256+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i8> [[DIV1]], <2 x i8> [[DIV0]], <2 x i32> <i32 0, i32 3>
257+
; CHECK-NEXT: ret <2 x i8> [[R]]
258+
;
259+
%add = xor i8 %inp, 5
260+
%v0 = insertelement <2 x i8> %any, i8 %inp, i64 0
261+
%v = insertelement <2 x i8> %v0, i8 %add, i64 1
262+
%div0 = add nsw <2 x i8> <i8 12, i8 1>, %v
263+
%div1 = xor <2 x i8> %v, <i8 123, i8 12>
264+
%r = shufflevector <2 x i8> %div1, <2 x i8> %div0, <2 x i32> <i32 0, i32 3>
265+
ret <2 x i8> %r
266+
}

0 commit comments

Comments
 (0)