[llvm] [ISel] Introduce llvm.clmul intrinsic (PR #168731)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 20 09:24:36 PST 2025
================
@@ -8302,6 +8302,57 @@ SDValue TargetLowering::expandFunnelShift(SDNode *Node,
return DAG.getNode(ISD::OR, DL, VT, ShX, ShY);
}
+SDValue TargetLowering::expandCLMUL(SDNode *Node, SelectionDAG &DAG) const {
+ SDLoc DL(Node);
+ EVT VT = Node->getValueType(0);
+ SDValue X = Node->getOperand(0);
+ SDValue Y = Node->getOperand(1);
+ unsigned BW = VT.getScalarSizeInBits();
+ unsigned Opcode = Node->getOpcode();
+
+ if (VT.isVector() &&
+ isOperationLegalOrCustomOrPromote(Opcode, VT.getVectorElementType()))
+ return DAG.UnrollVectorOp(Node);
+
+ switch (Opcode) {
+ case ISD::CLMUL: {
+ SDValue Res = DAG.getConstant(0, DL, VT);
+ for (unsigned I = 0; I < BW; ++I) {
+ SDValue Mask = DAG.getConstant(APInt::getOneBitSet(BW, I), DL, VT);
+ SDValue YMasked = DAG.getNode(ISD::AND, DL, VT, Y, Mask);
+ SDValue Mul = DAG.getNode(ISD::MUL, DL, VT, X, YMasked);
+ Res = DAG.getNode(ISD::XOR, DL, VT, Res, Mul);
+ }
+ return Res;
+ }
+ case ISD::CLMULR:
+ case ISD::CLMULH: {
+ EVT ExtVT = EVT::getIntegerVT(*DAG.getContext(), 2 * BW);
+ // For example, ExtVT = i64 based operations aren't legal on rv32; use
----------------
topperc wrote:
"rv32" should not appear in target independent code
https://github.com/llvm/llvm-project/pull/168731
More information about the llvm-commits
mailing list