[llvm] [IR] Add llvm `clmul` intrinsic (PR #140301)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 00:53:11 PDT 2025


================
@@ -8131,6 +8131,41 @@ 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 V1 = Node->getOperand(0);
+  SDValue V2 = Node->getOperand(1);
+  unsigned NumBitsPerElt = VT.getScalarSizeInBits();
+
+  EVT SetCCType =
+      getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+  // Only expand vector types if we have the appropriate vector bit operations.
+  if (VT.isVector() && (!isPowerOf2_32(NumBitsPerElt) ||
+                        (!isOperationLegalOrCustom(ISD::SRL, VT) ||
+                        !isOperationLegalOrCustom(ISD::SHL, VT) ||
+                        !isOperationLegalOrCustom(ISD::XOR, VT) ||
+                        !isOperationLegalOrCustom(ISD::AND, VT) ||
+                        !isOperationLegalOrCustom(ISD::SELECT, VT))))
+    return SDValue();
----------------
arsenm wrote:

This should never fail. This should expand the operation to something. You have the choice between emitting vector ops, or directly scalarizing, and this should at least fall back to scalarize 

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


More information about the llvm-commits mailing list