[llvm] [RISCV] Use `experimental-p` extension for zero-extended narrow unsigned types (PR #213260)

Rajveer Singh Bharadwaj via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 05:07:16 PDT 2026


================
@@ -557,6 +559,113 @@ void RISCVDAGToDAGISel::selectXSfmmVSET(SDNode *Node) {
   }
 }
 
+bool RISCVDAGToDAGISel::tryPExtNarrowUnsigned(SDNode *Node) {
+  using namespace SDPatternMatch;
+
+  EVT VT = Node->getValueType(0);
+  SDLoc DL(Node);
+
+  APInt ConstMask;
+
+  if (sd_match(Node,
+               m_And(m_Add(m_Value(), m_Value()), m_ConstInt(ConstMask)))) {
+    uint64_t ConstMaskVal = ConstMask.getZExtValue();
+    if (ConstMaskVal != 255 && ConstMaskVal != 65535)
+      return false;
+
+    uint64_t PAddOpcode = (ConstMaskVal == 255) ? RISCV::PADD_B : RISCV::PADD_H;
+    uint64_t MinZeroBits = (ConstMaskVal == 255) ? 24 : 16;
----------------
Rajveer100 wrote:

Do we want to handle (32+32) on RV64:

```riscv
add	a0, a1, a0
zext.w	a0, a0
ret
```

Wouldn't it be valid to optimize this to `padd.w`?

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


More information about the llvm-commits mailing list