[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.
This commit is contained in:
Craig Topper 2023-10-02 09:13:33 -07:00 committed by GitHub
parent c2fd3ebe83
commit 8f4ffbbaf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3530,8 +3530,8 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
(NumElts <= 4 || VT.getSizeInBits() > Subtarget.getRealMinVLen())) {
unsigned SignBits = DAG.ComputeNumSignBits(Op);
if (EltBitSize - SignBits < 8) {
SDValue Source =
DAG.getNode(ISD::TRUNCATE, DL, VT.changeVectorElementType(MVT::i8), Op);
SDValue Source = DAG.getBuildVector(VT.changeVectorElementType(MVT::i8),
DL, Op->ops());
Source = convertToScalableVector(ContainerVT.changeVectorElementType(MVT::i8),
Source, DAG, Subtarget);
SDValue Res = DAG.getNode(RISCVISD::VSEXT_VL, DL, ContainerVT, Source, Mask, VL);