[llvm] [RISCV] Create new build vector instead of relying on getNode constan… (PR #67944)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 1 20:53:34 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
<details>
<summary>Changes</summary>
…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.
---
Full diff: https://github.com/llvm/llvm-project/pull/67944.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+2-2)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index fb7ed79c7888421..c9d74856e0a15aa 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/67944
More information about the llvm-commits
mailing list