[llvm] [RISCV] Fold extract_vector_elt of a load into the scalar load (PR #76151)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 26 15:11:38 PST 2023


================
@@ -14466,6 +14466,59 @@ 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();
+  // extract_vec_elt (load X), C --> scalar load (X+C)
+  if (LoadVec && ISD::isNormalLoad(LoadVec) && LoadVec->isSimple()) {
----------------
topperc wrote:

Invert this `if` and early out.

https://github.com/llvm/llvm-project/pull/76151


More information about the llvm-commits mailing list