Skip to content

Commit d51855f

Browse files
authored
[RISCV] Fix assertion failure from performBUILD_VECTORCombine when the binop is a shift. (#69349)
The RHS of a shift can have a different type than the LHS. If there are undefs in the vector, we need the undef added to the RHS to match the type of any shift amounts that are also added to the vector. For now just don't add shifts if their RHS and LHS don't match.
1 parent 8175190 commit d51855f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13717,7 +13717,7 @@ static SDValue performSELECTCombine(SDNode *N, SelectionDAG &DAG,
1371713717
return tryFoldSelectIntoOp(N, DAG, FalseVal, TrueVal, /*Swapped*/true);
1371813718
}
1371913719

13720-
/// IF we have a build_vector where each lane is binop X, C, where C
13720+
/// If we have a build_vector where each lane is binop X, C, where C
1372113721
/// is a constant (but not necessarily the same constant on all lanes),
1372213722
/// form binop (build_vector x1, x2, ...), (build_vector c1, c2, c3, ..).
1372313723
/// We assume that materializing a constant build vector will be no more
@@ -13763,6 +13763,10 @@ static SDValue performBUILD_VECTORCombine(SDNode *N, SelectionDAG &DAG,
1376313763
if (!isa<ConstantSDNode>(Op.getOperand(1)) &&
1376413764
!isa<ConstantFPSDNode>(Op.getOperand(1)))
1376513765
return SDValue();
13766+
// FIXME: Return failure if the RHS type doesn't match the LHS. Shifts may
13767+
// have different LHS and RHS types.
13768+
if (Op.getOperand(0).getValueType() != Op.getOperand(1).getValueType())
13769+
return SDValue();
1376613770
RHSOps.push_back(Op.getOperand(1));
1376713771
}
1376813772

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-buildvec-of-binop.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,15 @@ define <4 x i32> @add_general_splat(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
442442
%v3 = insertelement <4 x i32> %v2, i32 %e3, i32 3
443443
ret <4 x i32> %v3
444444
}
445+
446+
; This test previously failed with an assertion failure because constant shift
447+
; amounts are type legalized early.
448+
define void @buggy(i32 %0) #0 {
449+
entry:
450+
%mul.us.us.i.3 = shl i32 %0, 1
451+
%1 = insertelement <4 x i32> zeroinitializer, i32 %mul.us.us.i.3, i64 0
452+
%2 = or <4 x i32> %1, <i32 1, i32 1, i32 1, i32 1>
453+
%3 = shufflevector <4 x i32> %2, <4 x i32> zeroinitializer, <4 x i32> zeroinitializer
454+
store <4 x i32> %3, ptr null, align 16
455+
ret void
456+
}

0 commit comments

Comments
 (0)