[llvm-branch-commits] [llvm] [RISCV][P-ext] Combine RISCVISD::PMULH_H_B0/PMULH_W_H0/MULH_H0 into a single ISD opcode. NFC (PR #237807)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Nov 1 17:06:10 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
This matches how MHACC_HALF opcodes are implemented.
I adjusted the type profile for MHACC_HALF for consistency.
---
Full diff: https://github.com/llvm/llvm-project/pull/237807.diff
2 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+12-49)
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoP.td (+30-39)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 0b849ad34a205..2f70fca3b0092 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -12559,57 +12559,21 @@ static unsigned getRVPMulHighPartsOpcode(unsigned IntNo) {
default:
llvm_unreachable("Unexpected RISC-V multiply-high-parts intrinsic");
case Intrinsic::riscv_pmulh_b0:
- return RISCVISD::PMULH_H_B0;
- case Intrinsic::riscv_pmulh_b1:
- return RISCVISD::PMULH_H_B1;
- case Intrinsic::riscv_pmulhsu_b0:
- return RISCVISD::PMULHSU_H_B0;
- case Intrinsic::riscv_pmulhsu_b1:
- return RISCVISD::PMULHSU_H_B1;
- }
-}
-
-/// Return the word multiply-high-parts node for a word multiply-high-parts
-/// intrinsic. The scalar spelling maps to the same node; its product is the
-/// first element.
-static unsigned getRVPMulHighPartsWOpcode(unsigned IntNo) {
- switch (IntNo) {
- default:
- llvm_unreachable("Unexpected RISC-V word multiply-high-parts intrinsic");
- case Intrinsic::riscv_pmulh_h0:
- case Intrinsic::riscv_mulh_h0:
- return RISCVISD::PMULH_W_H0;
- case Intrinsic::riscv_pmulh_h1:
- case Intrinsic::riscv_mulh_h1:
- return RISCVISD::PMULH_W_H1;
- case Intrinsic::riscv_pmulhsu_h0:
- case Intrinsic::riscv_mulhsu_h0:
- return RISCVISD::PMULHSU_W_H0;
- case Intrinsic::riscv_pmulhsu_h1:
- case Intrinsic::riscv_mulhsu_h1:
- return RISCVISD::PMULHSU_W_H1;
- }
-}
-
-/// Return the scalar halfword multiply-high-parts node for \p IntNo (RV32
-/// mulh.h0/h1). The packed word spelling maps to the same node; its product
-/// is the first element.
-static unsigned getRVPScalarMulHighPartsOpcode(unsigned IntNo) {
- switch (IntNo) {
- default:
- llvm_unreachable("Unexpected RISC-V scalar multiply-high-parts intrinsic");
case Intrinsic::riscv_pmulh_h0:
case Intrinsic::riscv_mulh_h0:
- return RISCVISD::MULH_H0;
+ return RISCVISD::MULH_HALF_0;
+ case Intrinsic::riscv_pmulh_b1:
case Intrinsic::riscv_pmulh_h1:
case Intrinsic::riscv_mulh_h1:
- return RISCVISD::MULH_H1;
+ return RISCVISD::MULH_HALF_1;
+ case Intrinsic::riscv_pmulhsu_b0:
case Intrinsic::riscv_pmulhsu_h0:
case Intrinsic::riscv_mulhsu_h0:
- return RISCVISD::MULHSU_H0;
+ return RISCVISD::MULHSU_HALF_0;
+ case Intrinsic::riscv_pmulhsu_b1:
case Intrinsic::riscv_pmulhsu_h1:
case Intrinsic::riscv_mulhsu_h1:
- return RISCVISD::MULHSU_H1;
+ return RISCVISD::MULHSU_HALF_1;
}
}
@@ -13641,7 +13605,7 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
EVT VT = Op.getValueType();
SDValue Rs1 = Op.getOperand(1);
SDValue Rs2 = Op.getOperand(2);
- unsigned Opc = getRVPMulHighPartsWOpcode(IntNo);
+ unsigned Opc = getRVPMulHighPartsOpcode(IntNo);
// RV32 has no single instruction for a 64-bit packed word multiply-high
// parts. Split v2i32 into two scalar operations, one per result word.
@@ -13650,9 +13614,8 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
return DAG.getExtractVectorElt(DL, MVT::i32, V, Idx);
};
auto [Rs2Lo, Rs2Hi] = DAG.SplitVector(Rs2, DL);
- unsigned SOpc = getRVPScalarMulHighPartsOpcode(IntNo);
- SDValue Lo = DAG.getNode(SOpc, DL, MVT::i32, Extract(Rs1, 0), Rs2Lo);
- SDValue Hi = DAG.getNode(SOpc, DL, MVT::i32, Extract(Rs1, 1), Rs2Hi);
+ SDValue Lo = DAG.getNode(Opc, DL, MVT::i32, Extract(Rs1, 0), Rs2Lo);
+ SDValue Hi = DAG.getNode(Opc, DL, MVT::i32, Extract(Rs1, 1), Rs2Hi);
return DAG.getNode(ISD::BUILD_VECTOR, DL, VT, Lo, Hi);
}
@@ -13698,7 +13661,7 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
SDValue Rs1 = Op.getOperand(1);
SDValue Rs2 = Op.getOperand(2);
- unsigned Opc = getRVPScalarMulHighPartsOpcode(IntNo);
+ unsigned Opc = getRVPMulHighPartsOpcode(IntNo);
return DAG.getNode(Opc, DL, VT, Rs1, Rs2);
}
case Intrinsic::riscv_pm4add:
@@ -18272,7 +18235,7 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
SDValue Undef = DAG.getUNDEF(SrcVT);
SDValue Rs1 = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v4i16,
N->getOperand(2), Undef);
- SDValue Res = DAG.getNode(getRVPMulHighPartsWOpcode(IntNo), DL,
+ SDValue Res = DAG.getNode(getRVPMulHighPartsOpcode(IntNo), DL,
MVT::v2i32, Rd, Rs1);
Results.push_back(DAG.getExtractVectorElt(DL, MVT::i32, Res, 0));
return;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
index e5f456ed891ac..c3db63c1d4e40 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoP.td
@@ -1895,25 +1895,16 @@ def riscv_pmulsu_halves_00
def riscv_pmulsu_halves_11
: RVSDNode<"PMULSU_HALVES_11", SDT_RISCVPackedWideningMulByHalves>;
-// Multiply high parts. The result and rs1 keep the full element width; rs2
+// Multiply high half. The result and rs1 keep the full element width; rs2
// is the vector of half-width elements selecting the part to multiply. The
// scalar form keeps a single product (RV32 mulh.h0/h1).
-def SDT_RISCVMulHighParts
- : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisVec<2>]>;
-def riscv_mulh_h0 : RVSDNode<"MULH_H0", SDT_RISCVMulHighParts>;
-def riscv_mulh_h1 : RVSDNode<"MULH_H1", SDT_RISCVMulHighParts>;
-def riscv_mulhsu_h0 : RVSDNode<"MULHSU_H0", SDT_RISCVMulHighParts>;
-def riscv_mulhsu_h1 : RVSDNode<"MULHSU_H1", SDT_RISCVMulHighParts>;
-
-def riscv_pmulh_h_b0 : RVSDNode<"PMULH_H_B0", SDT_RISCVMulHighParts>;
-def riscv_pmulh_h_b1 : RVSDNode<"PMULH_H_B1", SDT_RISCVMulHighParts>;
-def riscv_pmulhsu_h_b0 : RVSDNode<"PMULHSU_H_B0", SDT_RISCVMulHighParts>;
-def riscv_pmulhsu_h_b1 : RVSDNode<"PMULHSU_H_B1", SDT_RISCVMulHighParts>;
-
-def riscv_pmulh_w_h0 : RVSDNode<"PMULH_W_H0", SDT_RISCVMulHighParts>;
-def riscv_pmulh_w_h1 : RVSDNode<"PMULH_W_H1", SDT_RISCVMulHighParts>;
-def riscv_pmulhsu_w_h0 : RVSDNode<"PMULHSU_W_H0", SDT_RISCVMulHighParts>;
-def riscv_pmulhsu_w_h1 : RVSDNode<"PMULHSU_W_H1", SDT_RISCVMulHighParts>;
+def SDT_RISCVMulHighHalf
+ : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisVec<2>,
+ SDTCisSameSizeAs<0, 2>]>;
+def riscv_mulh_half_0 : RVSDNode<"MULH_HALF_0", SDT_RISCVMulHighHalf>;
+def riscv_mulh_half_1 : RVSDNode<"MULH_HALF_1", SDT_RISCVMulHighHalf>;
+def riscv_mulhsu_half_0 : RVSDNode<"MULHSU_HALF_0", SDT_RISCVMulHighHalf>;
+def riscv_mulhsu_half_1 : RVSDNode<"MULHSU_HALF_1", SDT_RISCVMulHighHalf>;
// Packed multiplication with widening horizontal addition.
def SDT_RISCVPackedWideningHorizontalAdd
@@ -2059,14 +2050,14 @@ def riscv_mhraccsu : RVSDNode<"MHRACCSU", SDT_RISCVSameTernary>;
// Multiply high accumulate operations. The packed form's third operand has
// smaller elements than the result; the scalar form (RV32) accumulates one
// word of the result.
-def SDT_RISCVMulHighAccumulateByHalves
+def SDT_RISCVMulHighAccumulateHalf
: SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
- SDTCisSameAs<0, 2>,
+ SDTCisSameAs<0, 2>, SDTCisVec<3>,
SDTCisSameSizeAs<0, 3>]>;
-def riscv_mhacc_half_0 : RVSDNode<"MHACC_HALF_0", SDT_RISCVMulHighAccumulateByHalves>;
-def riscv_mhacc_half_1 : RVSDNode<"MHACC_HALF_1", SDT_RISCVMulHighAccumulateByHalves>;
-def riscv_mhaccsu_half_0 : RVSDNode<"MHACCSU_HALF_0", SDT_RISCVMulHighAccumulateByHalves>;
-def riscv_mhaccsu_half_1 : RVSDNode<"MHACCSU_HALF_1", SDT_RISCVMulHighAccumulateByHalves>;
+def riscv_mhacc_half_0 : RVSDNode<"MHACC_HALF_0", SDT_RISCVMulHighAccumulateHalf>;
+def riscv_mhacc_half_1 : RVSDNode<"MHACC_HALF_1", SDT_RISCVMulHighAccumulateHalf>;
+def riscv_mhaccsu_half_0 : RVSDNode<"MHACCSU_HALF_0", SDT_RISCVMulHighAccumulateHalf>;
+def riscv_mhaccsu_half_1 : RVSDNode<"MHACCSU_HALF_1", SDT_RISCVMulHighAccumulateHalf>;
// Multiply packed elements and horizontally combine each adjacent group.
def SDT_RISCVHorizontalMul
@@ -2538,17 +2529,17 @@ let Predicates = [HasStdExtP] in {
(PMULSU_H_B11 GPR:$rs1, GPR:$rs2)>;
// Packed byte multiply-high parts patterns.
- def : Pat<(XLenVecI16VT (riscv_pmulh_h_b0 (XLenVecI16VT GPR:$rs1),
- (XLenVecI8VT GPR:$rs2))),
+ def : Pat<(XLenVecI16VT (riscv_mulh_half_0 (XLenVecI16VT GPR:$rs1),
+ (XLenVecI8VT GPR:$rs2))),
(PMULH_H_B0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(XLenVecI16VT (riscv_pmulh_h_b1 (XLenVecI16VT GPR:$rs1),
- (XLenVecI8VT GPR:$rs2))),
+ def : Pat<(XLenVecI16VT (riscv_mulh_half_1 (XLenVecI16VT GPR:$rs1),
+ (XLenVecI8VT GPR:$rs2))),
(PMULH_H_B1 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(XLenVecI16VT (riscv_pmulhsu_h_b0 (XLenVecI16VT GPR:$rs1),
- (XLenVecI8VT GPR:$rs2))),
+ def : Pat<(XLenVecI16VT (riscv_mulhsu_half_0 (XLenVecI16VT GPR:$rs1),
+ (XLenVecI8VT GPR:$rs2))),
(PMULHSU_H_B0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(XLenVecI16VT (riscv_pmulhsu_h_b1 (XLenVecI16VT GPR:$rs1),
- (XLenVecI8VT GPR:$rs2))),
+ def : Pat<(XLenVecI16VT (riscv_mulhsu_half_1 (XLenVecI16VT GPR:$rs1),
+ (XLenVecI8VT GPR:$rs2))),
(PMULHSU_H_B1 GPR:$rs1, GPR:$rs2)>;
let append Predicates = [IsRV32] in {
@@ -2573,13 +2564,13 @@ let append Predicates = [IsRV32] in {
def : PatMulParts<int_riscv_mulsu_11, MULSU_H11, i32, v2i16>;
// Scalar halfword multiply-high parts patterns.
- def : Pat<(i32 (riscv_mulh_h0 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
+ def : Pat<(i32 (riscv_mulh_half_0 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
(MULH_H0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(i32 (riscv_mulh_h1 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
+ def : Pat<(i32 (riscv_mulh_half_1 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
(MULH_H1 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(i32 (riscv_mulhsu_h0 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
+ def : Pat<(i32 (riscv_mulhsu_half_0 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
(MULHSU_H0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(i32 (riscv_mulhsu_h1 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
+ def : Pat<(i32 (riscv_mulhsu_half_1 (i32 GPR:$rs1), (v2i16 GPR:$rs2))),
(MULHSU_H1 GPR:$rs1, GPR:$rs2)>;
def : PatGpr<bitreverse, REV_RV32>;
@@ -3515,13 +3506,13 @@ let append Predicates = [IsRV64] in {
def : PatMulParts<int_riscv_mulsu_11, MULSU_W11, i64, v2i32>;
// Packed word multiply-high parts patterns.
- def : Pat<(v2i32 (riscv_pmulh_w_h0 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
+ def : Pat<(v2i32 (riscv_mulh_half_0 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
(PMULH_W_H0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(v2i32 (riscv_pmulh_w_h1 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
+ def : Pat<(v2i32 (riscv_mulh_half_1 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
(PMULH_W_H1 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(v2i32 (riscv_pmulhsu_w_h0 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
+ def : Pat<(v2i32 (riscv_mulhsu_half_0 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
(PMULHSU_W_H0 GPR:$rs1, GPR:$rs2)>;
- def : Pat<(v2i32 (riscv_pmulhsu_w_h1 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
+ def : Pat<(v2i32 (riscv_mulhsu_half_1 (v2i32 GPR:$rs1), (v4i16 GPR:$rs2))),
(PMULHSU_W_H1 GPR:$rs1, GPR:$rs2)>;
// 32-bit multiply high patterns
``````````
</details>
https://github.com/llvm/llvm-project/pull/237807
More information about the llvm-branch-commits
mailing list