[llvm] [X86] Lower i64 vector division and remainder through float division (PR #215043)

Adam Scott via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 00:46:52 PDT 2026


================
@@ -50738,6 +50695,156 @@ static SDValue combineIntDivRem(SDNode *N, SelectionDAG &DAG,
                      DAG.getNode(ISD::MUL, DL, VT, Q, Divisor));
 }
 
+// i64: the quotient doesn't fit f64 exactly, so build it from two
+// rounded-down reciprocal multiplies, one of the dividend and one of its
+// remainder. {rd/ru-sae} rounding is 512-bit so AVX512DQ only.
+static SDValue combineIntDivRemViaFPReciprocal(SDNode *N, bool IsSigned,
+                                               bool IsRem, SelectionDAG &DAG,
+                                               const X86Subtarget &Subtarget,
+                                               const SDLoc &DL) {
+  EVT VT = N->getValueType(0);
+  SDValue Dividend = N->getOperand(0);
+  SDValue Divisor = N->getOperand(1);
+
+  if (VT != MVT::v2i64 && VT != MVT::v4i64 && VT != MVT::v8i64)
----------------
as4230 wrote:

Sort of. It doesn't bail early on non pow2 shapes anymore so v3i64 for example reaches this directly now. I widened those to the next power of two so every lane folds in one chain. That gets rid of the scalar divq the legalizer used to leave behind from splitting v3i64 into a v2i64 plus a scalar.

The dispatcher already guarantees the element size is 64 so the check itself can just be `(VT.getSizeInBits() > 512 || NumElts < 2)`

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


More information about the llvm-commits mailing list