@@ -6481,18 +6481,6 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
64816481 SDValue N0 = N->getOperand (0 );
64826482 SDValue N1 = N->getOperand (1 );
64836483
6484- // Try to use leading zeros of the dividend to reduce the multiplier and
6485- // 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- }
6495-
64966484 bool UseNPQ = false , UsePreShift = false , UsePostShift = false ;
64976485 SmallVector<SDValue, 16 > PreShifts, PostShifts, MagicFactors, NPQFactors;
64986486
@@ -6509,8 +6497,14 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
65096497 PreShift = PostShift = DAG.getUNDEF (ShSVT);
65106498 MagicFactor = NPQFactor = DAG.getUNDEF (SVT);
65116499 } else {
6500+ // Try to use leading zeros of the dividend to reduce the multiplier and
6501+ // avoid expensive fixups.
6502+ unsigned KnownLeadingZeros =
6503+ DAG.computeKnownBits (N0).countMinLeadingZeros ();
6504+
65126505 UnsignedDivisionByConstantInfo magics =
6513- UnsignedDivisionByConstantInfo::get (Divisor, LeadingZeros);
6506+ UnsignedDivisionByConstantInfo::get (
6507+ Divisor, std::min (KnownLeadingZeros, Divisor.countl_zero ()));
65146508
65156509 MagicFactor = DAG.getConstant (magics.Magic , dl, SVT);
65166510
0 commit comments