Skip to content

Commit 138ff5a

Browse files
tlivelymemfrob
authored andcommitted
[WebAssembly] Fix bug in custom shuffle combine
Summary: The code previously assumed the source of the bitcast in the combined pattern was a vector type, but this is not always true. This patch adds a check to avoid an assertion failure in that case. Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80164
1 parent 0d947b4 commit 138ff5a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,8 @@ performVECTOR_SHUFFLECombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
17141714

17151715
// Hoist vector bitcasts that don't change the number of lanes out of unary
17161716
// shuffles, where they are less likely to get in the way of other combines.
1717-
// (shuffle (vNxT1 (bitcast (vNxT0 x))), undef, mask) ->
1718-
// (vNxT1 (bitcast (vNxt0 (shuffle x, undef, mask))))
1717+
// (shuffle (vNxT1 (bitcast (vNxT0 x))), undef, mask) ->
1718+
// (vNxT1 (bitcast (vNxT0 (shuffle x, undef, mask))))
17191719
SDValue Bitcast = N->getOperand(0);
17201720
if (Bitcast.getOpcode() != ISD::BITCAST)
17211721
return SDValue();
@@ -1724,7 +1724,8 @@ performVECTOR_SHUFFLECombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
17241724
SDValue CastOp = Bitcast.getOperand(0);
17251725
MVT SrcType = CastOp.getSimpleValueType();
17261726
MVT DstType = Bitcast.getSimpleValueType();
1727-
if (SrcType.getVectorNumElements() != DstType.getVectorNumElements())
1727+
if (!SrcType.is128BitVector() ||
1728+
SrcType.getVectorNumElements() != DstType.getVectorNumElements())
17281729
return SDValue();
17291730
SDValue NewShuffle = DAG.getVectorShuffle(
17301731
SrcType, SDLoc(N), CastOp, DAG.getUNDEF(SrcType), Shuffle->getMask());

llvm/test/CodeGen/WebAssembly/simd-shuffle-bitcast.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ define <4 x i32> @f32x4_splat(float %x) {
1717
%b = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> zeroinitializer
1818
ret <4 x i32> %b
1919
}
20+
21+
; CHECK-LABEL: not_a_vec:
22+
; CHECK-NEXT: .functype not_a_vec (i64, i64) -> (v128){{$}}
23+
; CHECK-NEXT: i64x2.splat $push[[L1:[0-9]+]]=, $0{{$}}
24+
; CHECK-NEXT: v8x16.shuffle $push[[R:[0-9]+]]=, $pop[[L1]], $2, 0, 1, 2, 3
25+
; CHECK-NEXT: return $pop[[R]]
26+
define <4 x i32> @not_a_vec(i128 %x) {
27+
%a = bitcast i128 %x to <4 x i32>
28+
%b = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> zeroinitializer
29+
ret <4 x i32> %b
30+
}

0 commit comments

Comments
 (0)