[llvm] [RISCV] Fold (vslide1up undef, v, (extract_elt x, 0)) into (vslideup x, v, 1) (PR #154847)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 00:04:40 PDT 2025


================
@@ -21151,6 +21151,36 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
       return N->getOperand(0);
     break;
   }
+  case RISCVISD::VSLIDE1UP_VL:
+  case RISCVISD::VFSLIDE1UP_VL: {
+    using namespace SDPatternMatch;
+    SDValue SrcVec;
+    SDLoc DL(N);
+    MVT VT = N->getSimpleValueType(0);
+    // If the scalar we're sliding in was extracted from the first element of a
+    // vector, we can use that vector as the passthru in a normal slideup of 1.
+    // This saves us an extract_element instruction (i.e. vfmv.f.s, vmv.x.s).
+    if (N->getOperand(0).isUndef() &&
+        sd_match(N->getOperand(2),
+                 m_AnyOf(m_ExtractElt(m_Value(SrcVec), m_Zero()),
+                         m_Node(RISCVISD::VMV_X_S, m_Value(SrcVec))))) {
----------------
lukel97 wrote:

Nit you can do an early return instead and avoid the nesting


```suggestion
    if (!N->getOperand(0).isUndef() ||
        !sd_match(N->getOperand(2),
                 m_AnyOf(m_ExtractElt(m_Value(SrcVec), m_Zero()),
                         m_Node(RISCVISD::VMV_X_S, m_Value(SrcVec)))))
       break;
```

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


More information about the llvm-commits mailing list