Skip to content

Commit 8f4ffbb

Browse files
authored
[RISCV] Create new build vector instead of relying on getNode constan… (#67944)
…t folding. We want to create a build_vector with narrower elements here. Normally getNode on the ISD::TRUNCATE will constant fold this to a new BUILD_VECTOR. If it doesn't constant fold, we end up with a cycle in the DAG because we truncate the node we are replacing. Constant folding can fail if one of the elements is an opaque constant. The failing case I saw involved an opaque constant created by a memset that was expanded. Not sure exactly what happened after that. This patch creates a new BUILD_VECTOR with the new type directly.
1 parent c2fd3eb commit 8f4ffbb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,8 +3530,8 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
35303530
(NumElts <= 4 || VT.getSizeInBits() > Subtarget.getRealMinVLen())) {
35313531
unsigned SignBits = DAG.ComputeNumSignBits(Op);
35323532
if (EltBitSize - SignBits < 8) {
3533-
SDValue Source =
3534-
DAG.getNode(ISD::TRUNCATE, DL, VT.changeVectorElementType(MVT::i8), Op);
3533+
SDValue Source = DAG.getBuildVector(VT.changeVectorElementType(MVT::i8),
3534+
DL, Op->ops());
35353535
Source = convertToScalableVector(ContainerVT.changeVectorElementType(MVT::i8),
35363536
Source, DAG, Subtarget);
35373537
SDValue Res = DAG.getNode(RISCVISD::VSEXT_VL, DL, ContainerVT, Source, Mask, VL);

0 commit comments

Comments
 (0)