Skip to content

Commit ec5b0ef

Browse files
authored
[RISCV] Truncate constants to eltwidth before checking simm5 when con… (llvm#67062)
…verting VMV_V_X to VMV_X_S. Instruction selection knows the bits past EltWidth are ignored, we should do the same here.
1 parent 2f91751 commit ec5b0ef

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14435,7 +14435,8 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1443514435
// patterns on rv32..
1443614436
ConstantSDNode *Const = dyn_cast<ConstantSDNode>(Scalar);
1443714437
if (isOneConstant(VL) && EltWidth <= Subtarget.getXLen() &&
14438-
(!Const || Const->isZero() || !isInt<5>(Const->getSExtValue())))
14438+
(!Const || Const->isZero() ||
14439+
!Const->getAPIntValue().sextOrTrunc(EltWidth).isSignedIntN(5)))
1443914440
return DAG.getNode(RISCVISD::VMV_S_X_VL, DL, VT, Passthru, Scalar, VL);
1444014441

1444114442
break;

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-shuffles.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,16 @@ define <8 x i8> @unmergable(<8 x i8> %v, <8 x i8> %w) {
781781
%res = shufflevector <8 x i8> %v, <8 x i8> %w, <8 x i32> <i32 2, i32 9, i32 4, i32 11, i32 6, i32 13, i32 8, i32 15>
782782
ret <8 x i8> %res
783783
}
784+
785+
; Make sure we use a vmv.v.i to load the mask constant.
786+
define <8 x i32> @shuffle_v8i32_2(<8 x i32> %x, <8 x i32> %y) {
787+
; CHECK-LABEL: shuffle_v8i32_2:
788+
; CHECK: # %bb.0:
789+
; CHECK-NEXT: vsetivli zero, 1, e8, mf8, ta, ma
790+
; CHECK-NEXT: vmv.v.i v0, -13
791+
; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
792+
; CHECK-NEXT: vmerge.vvm v8, v10, v8, v0
793+
; CHECK-NEXT: ret
794+
%s = shufflevector <8 x i32> %x, <8 x i32> %y, <8 x i32> <i32 0, i32 1, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
795+
ret <8 x i32> %s
796+
}

0 commit comments

Comments
 (0)