@@ -6483,15 +6483,7 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
64836483
64846484 // Try to use leading zeros of the dividend to reduce the multiplier and
64856485 // avoid expensive fixups.
6486- // TODO: Support vectors.
6487- unsigned LeadingZeros = 0 ;
6488- if (!VT.isVector () && isa<ConstantSDNode>(N1)) {
6489- assert (!isOneConstant (N1) && " Unexpected divisor" );
6490- LeadingZeros = DAG.computeKnownBits (N0).countMinLeadingZeros ();
6491- // UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros in
6492- // the dividend exceeds the leading zeros for the divisor.
6493- LeadingZeros = std::min (LeadingZeros, N1->getAsAPIntVal ().countl_zero ());
6494- }
6486+ unsigned KnownLeadingZeros = DAG.computeKnownBits (N0).countMinLeadingZeros ();
64956487
64966488 bool UseNPQ = false , UsePreShift = false , UsePostShift = false ;
64976489 SmallVector<SDValue, 16 > PreShifts, PostShifts, MagicFactors, NPQFactors;
@@ -6510,7 +6502,8 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
65106502 MagicFactor = NPQFactor = DAG.getUNDEF (SVT);
65116503 } else {
65126504 UnsignedDivisionByConstantInfo magics =
6513- UnsignedDivisionByConstantInfo::get (Divisor, LeadingZeros);
6505+ UnsignedDivisionByConstantInfo::get (
6506+ Divisor, std::min (KnownLeadingZeros, Divisor.countl_zero ()));
65146507
65156508 MagicFactor = DAG.getConstant (magics.Magic , dl, SVT);
65166509
0 commit comments