[llvm] [IR] Add llvm `clmul` intrinsic (PR #140301)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 10:29:29 PDT 2025
================
@@ -5417,6 +5422,36 @@ void DAGTypeLegalizer::ExpandIntRes_FunnelShift(SDNode *N, SDValue &Lo,
Hi = DAG.getNode(Opc, DL, HalfVT, Select3, Select2, NewShAmt);
}
+void DAGTypeLegalizer::ExpandIntRes_CLMUL(SDNode *N, SDValue &Lo,
+ SDValue &Hi) {
+ // Values numbered from least significant to most significant.
+ SDValue LL, LH, RL, RH;
+ GetExpandedInteger(N->getOperand(0), LL, LH);
+ GetExpandedInteger(N->getOperand(1), RL, RH);
+ EVT HalfVT = LL.getValueType();
+ SDLoc DL(N);
+
+ // CLMUL is carryless so Lo is computed from the low half
+ Lo = DAG.getNode(ISD::CLMUL, DL, HalfVT, LL, RL);
+ // the high bits not included in CLMUL(A,B) can be computed by
+ // BITREVERSE(CLMUL(BITREVERSE(A), BITREVERSE(B))) >> 1
+ // Therefore we can compute the 2 hi/lo cross products
+ // and the the overflow of the low product
+ // and xor them together to compute HI
+ // TODO: if the target supports a widening CLMUL or a CLMULH we should probably use that
+ SDValue BitRevLL = DAG.getNode(ISD::BITREVERSE, DL, HalfVT, LL);
+ SDValue BitRevRL = DAG.getNode(ISD::BITREVERSE, DL, HalfVT, RL);
+ SDValue BitRevLoHi = DAG.getNode(ISD::CLMUL, DL, HalfVT, BitRevLL, BitRevRL);
+ SDValue LoHi = DAG.getNode(ISD::BITREVERSE, DL, HalfVT, BitRevLoHi);
+ SDValue One = DAG.getShiftAmountConstant(1, HalfVT, DL);
+ Hi = DAG.getNode(ISD::SRL, DL, HalfVT, LoHi, One);
+
+ SDValue HITMP = DAG.getNode(ISD::CLMUL, DL, HalfVT, LL, RH);
----------------
topperc wrote:
HITMP -> HiTmp
https://github.com/llvm/llvm-project/pull/140301
More information about the llvm-commits
mailing list