[llvm] [RISCV][P-ext] Select plui.h/w and improve usage of pli.b/h/w. (PR #184937)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 20:47:34 PST 2026


================
@@ -2882,6 +2882,38 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
       return;
     }
 
+    unsigned EltSize = VT.getVectorElementType().getSizeInBits();
+    APInt Val = ConstNode->getAPIntValue().trunc(EltSize);
+
+    // Find the smallest splat.
+    if (Val.getBitWidth() > 16 && Val.isSplat(16))
+      Val = Val.trunc(16);
+    if (Val.getBitWidth() > 8 && Val.isSplat(8))
+      Val = Val.trunc(8);
+
+    EltSize = Val.getBitWidth();
+    int64_t Imm = Val.getSExtValue();
+
+    unsigned Opc = 0;
+    if (EltSize == 8) {
+      Opc = RISCV::PLI_B;
+    } else if (isInt<10>(Imm)) {
+      Opc = EltSize == 32 ? RISCV::PLI_W : RISCV::PLI_H;
+    } else if (EltSize == 16 && (Imm & 0x3f) == 0) {
+      Opc = RISCV::PLUI_H;
+      Imm = Imm >> 10;
----------------
topperc wrote:

you're right. I mixed up the 10 and 6. Thanks!

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


More information about the llvm-commits mailing list