Skip to content

Commit

Permalink
[VectorCombine][X86] Extend bitcast(shuffle(x,y)) test coverage
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
RKSimon committed Apr 11, 2024
1 parent cca30df commit b60974d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions llvm/test/Transforms/VectorCombine/X86/shuffle.ll
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,48 @@ define <16 x i8> @bitcast_shuf_uses(<4 x i32> %v) {
ret <16 x i8> %r
}

; shuffle of 2 operands removes bitcasts

define <4 x i64> @bitcast_shuf_remove_bitcasts(<2 x i64> %a0, <2 x i64> %a1) {
; CHECK-LABEL: @bitcast_shuf_remove_bitcasts(
; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i64> [[A0:%.*]], <2 x i64> [[A1:%.*]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
; CHECK-NEXT: ret <4 x i64> [[R]]
;
%bc0 = bitcast <2 x i64> %a0 to <4 x i32>
%bc1 = bitcast <2 x i64> %a1 to <4 x i32>
%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>
%r = bitcast <8 x i32> %shuf to <4 x i64>
ret <4 x i64> %r
}

; shuffle of 2 operands must reduce bitcasts

define <8 x i32> @bitcast_shuf_one_bitcast(<4 x i32> %a0, <2 x i64> %a1) {
; CHECK-LABEL: @bitcast_shuf_one_bitcast(
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
; 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>
; CHECK-NEXT: ret <8 x i32> [[R]]
;
%bc0 = bitcast <4 x i32> %a0 to <2 x i64>
%shuf = shufflevector <2 x i64> %bc0, <2 x i64> %a1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
%r = bitcast <4 x i64> %shuf to <8 x i32>
ret <8 x i32> %r
}

; TODO - Negative test - shuffle of 2 operands must not increase bitcasts

define <8 x i32> @bitcast_shuf_too_many_bitcasts(<2 x i64> %a0, <2 x i64> %a1) {
; CHECK-LABEL: @bitcast_shuf_too_many_bitcasts(
; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i64> [[A0:%.*]] to <4 x i32>
; CHECK-NEXT: [[TMP2:%.*]] = bitcast <2 x i64> [[A1:%.*]] to <4 x i32>
; 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>
; CHECK-NEXT: ret <8 x i32> [[R]]
;
%shuf = shufflevector <2 x i64> %a0, <2 x i64> %a1, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
%r = bitcast <4 x i64> %shuf to <8 x i32>
ret <8 x i32> %r
}

define <2 x i64> @PR35454_1(<2 x i64> %v) {
; SSE-LABEL: @PR35454_1(
; SSE-NEXT: [[BC:%.*]] = bitcast <2 x i64> [[V:%.*]] to <4 x i32>
Expand Down

0 comments on commit b60974d

Please sign in to comment.