[llvm] [CodeGen] Emit more efficient magic numbers for exact udivs (PR #87161)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 14 09:03:28 PDT 2024


================
@@ -6141,6 +6138,68 @@ static SDValue BuildExactSDIV(const TargetLowering &TLI, SDNode *N,
   return DAG.getNode(ISD::MUL, dl, VT, Res, Factor);
 }
 
+/// Given an exact UDIV by a constant, create a multiplication
+/// with the multiplicative inverse of the constant.
+static SDValue BuildExactUDIV(const TargetLowering &TLI, SDNode *N,
+                              const SDLoc &dl, SelectionDAG &DAG,
+                              SmallVectorImpl<SDNode *> &Created) {
+  SDValue Op0 = N->getOperand(0);
+  SDValue Op1 = N->getOperand(1);
+  EVT VT = N->getValueType(0);
+  EVT SVT = VT.getScalarType();
+  EVT ShVT = TLI.getShiftAmountTy(VT, DAG.getDataLayout());
----------------
AtariDreams wrote:

Done!

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


More information about the llvm-commits mailing list