Skip to content

Commit b60974d

Browse files
committed
[VectorCombine][X86] Extend bitcast(shuffle(x,y)) test coverage
As discussed on #87510 the intention is only to fold bitcast(shuffle(x,y)) -> shuffle(bitcast(x),bitcast(y)) if we won't actually increase the number of bitcasts (i.e. x or y is already bitcasted from the correct type).
1 parent cca30df commit b60974d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

llvm/test/Transforms/VectorCombine/X86/shuffle.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,48 @@ define <16 x i8> @bitcast_shuf_uses(<4 x i32> %v) {
121121
ret <16 x i8> %r
122122
}
123123

124+
; shuffle of 2 operands removes bitcasts
125+
126+
define <4 x i64> @bitcast_shuf_remove_bitcasts(<2 x i64> %a0, <2 x i64> %a1) {
127+
; CHECK-LABEL: @bitcast_shuf_remove_bitcasts(
128+
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i64> [[A0:%.*]], <2 x i64> [[A1:%.*]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
129+
; CHECK-NEXT: ret <4 x i64> [[R]]
130+
;
131+
%bc0 = bitcast <2 x i64> %a0 to <4 x i32>
132+
%bc1 = bitcast <2 x i64> %a1 to <4 x i32>
133+
%shuf = shufflevector <4 x i32> %bc0, <4 x i32> %bc1, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
134+
%r = bitcast <8 x i32> %shuf to <4 x i64>
135+
ret <4 x i64> %r
136+
}
137+
138+
; shuffle of 2 operands must reduce bitcasts
139+
140+
define <8 x i32> @bitcast_shuf_one_bitcast(<4 x i32> %a0, <2 x i64> %a1) {
141+
; CHECK-LABEL: @bitcast_shuf_one_bitcast(
142+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
143+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[A0:%.*]], <4 x i32> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
144+
; CHECK-NEXT: ret <8 x i32> [[R]]
145+
;
146+
%bc0 = bitcast <4 x i32> %a0 to <2 x i64>
147+
%shuf = shufflevector <2 x i64> %bc0, <2 x i64> %a1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
148+
%r = bitcast <4 x i64> %shuf to <8 x i32>
149+
ret <8 x i32> %r
150+
}
151+
152+
; TODO - Negative test - shuffle of 2 operands must not increase bitcasts
153+
154+
define <8 x i32> @bitcast_shuf_too_many_bitcasts(<2 x i64> %a0, <2 x i64> %a1) {
155+
; CHECK-LABEL: @bitcast_shuf_too_many_bitcasts(
156+
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A0:%.*]] to <4 x i32>
157+
; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
158+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> [[TMP2]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
159+
; CHECK-NEXT: ret <8 x i32> [[R]]
160+
;
161+
%shuf = shufflevector <2 x i64> %a0, <2 x i64> %a1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
162+
%r = bitcast <4 x i64> %shuf to <8 x i32>
163+
ret <8 x i32> %r
164+
}
165+
124166
define <2 x i64> @PR35454_1(<2 x i64> %v) {
125167
; SSE-LABEL: @PR35454_1(
126168
; SSE-NEXT: [[BC:%.*]] = bitcast <2 x i64> [[V:%.*]] to <4 x i32>

0 commit comments

Comments
 (0)