[llvm] [RISCV] Fold extract_vector_elt of a load into the scalar load (PR #76151)
Liao Chunyu via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 24 17:26:08 PST 2023
================
@@ -14466,6 +14466,40 @@ static SDValue performINSERT_VECTOR_ELTCombine(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, ConcatOps);
}
+static SDValue
+performEXTRACT_VECTOR_ELTCombine(SDNode *N, SelectionDAG &DAG,
+ const RISCVSubtarget &Subtarget,
+ const RISCVTargetLowering &TLI) {
+ SDValue InputVec = N->getOperand(0);
+ SDValue EltIdx = N->getOperand(1);
+ SDLoc DL(N);
+
+ EVT InVecVT = InputVec.getValueType();
+ if (InVecVT.isScalableVector())
+ return SDValue();
+
+ if (!InputVec.hasOneUse())
+ return SDValue();
+
+ auto *LoadVec = dyn_cast<LoadSDNode>(InputVec);
+ EVT VecEltVT = InVecVT.getVectorElementType();
+ auto *CIdx = dyn_cast<ConstantSDNode>(EltIdx);
+ // extract_vec_elt (load X), C --> scalar load (X+C)
+ if (LoadVec && CIdx && ISD::isNormalLoad(LoadVec) && LoadVec->isSimple()) {
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ SDValue NewPtr = TLI.getVectorElementPointer(DAG, LoadVec->getBasePtr(),
+ InVecVT, EltIdx);
+ unsigned PtrOff = VecEltVT.getSizeInBits() * CIdx->getZExtValue() / 8;
+ MachinePointerInfo MPI = LoadVec->getPointerInfo().getWithOffset(PtrOff);
+ Align Alignment = commonAlignment(LoadVec->getAlign(), PtrOff);
----------------
ChunyuLiao wrote:
I didn't find an example of needing unaligned access, can you help describe it if you have an example? thanks. @wangpc-pp
https://github.com/llvm/llvm-project/pull/76151
More information about the llvm-commits
mailing list