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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 11:09:15 PDT 2026


================
@@ -557,6 +559,126 @@ 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();
+
+    uint64_t PAddOpcode;
+    uint64_t MinZeroBits;
+
+    bool IsRV32 = Subtarget->isRV32();
+
+    switch (ConstMaskVal) {
+    case ((1ll << 8) - 1):
+      PAddOpcode = RISCV::PADD_B;
+      MinZeroBits = (IsRV32 ? 24 : 56);
+      break;
+    case ((1ll << 16) - 1):
+      PAddOpcode = RISCV::PADD_H;
+      MinZeroBits = (IsRV32 ? 16 : 48);
+      break;
+    default:
+      return false;
+    }
+
+    auto hasEnoughZeroBits = [MinZeroBits](SDNode *Node, SDValue Op) -> bool {
+      VTSDNode *ChainedNode = dyn_cast<VTSDNode>(Op);
+      if (!ChainedNode)
+        return false;
+
+      EVT FromTy = ChainedNode->getVT();
+      EVT ToTy = Node->getValueType(0);
+      return (ToTy.getSizeInBits() - FromTy.getSizeInBits()) >= MinZeroBits;
----------------
topperc wrote:

Sorry. I just mean flip the polarity so it's `MaxNonZeroBits` instead of `MinZeroBits`.

Then it becomes `return FromTy.getSizeInBits() <= MaxNonZeroBits`.

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


More information about the llvm-commits mailing list