@@ -6481,18 +6481,6 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
6481
6481
SDValue N0 = N->getOperand (0 );
6482
6482
SDValue N1 = N->getOperand (1 );
6483
6483
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
-
6496
6484
bool UseNPQ = false , UsePreShift = false , UsePostShift = false ;
6497
6485
SmallVector<SDValue, 16 > PreShifts, PostShifts, MagicFactors, NPQFactors;
6498
6486
@@ -6509,8 +6497,14 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
6509
6497
PreShift = PostShift = DAG.getUNDEF (ShSVT);
6510
6498
MagicFactor = NPQFactor = DAG.getUNDEF (SVT);
6511
6499
} 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
+
6512
6505
UnsignedDivisionByConstantInfo magics =
6513
- UnsignedDivisionByConstantInfo::get (Divisor, LeadingZeros);
6506
+ UnsignedDivisionByConstantInfo::get (
6507
+ Divisor, std::min (KnownLeadingZeros, Divisor.countl_zero ()));
6514
6508
6515
6509
MagicFactor = DAG.getConstant (magics.Magic , dl, SVT);
6516
6510
0 commit comments