Skip to content

Commit 8212034

Browse files
committed
[SelectionDAG] Remove redundant vector checks (NFC)
It turns out that the function already exits early if N1 is not a constant or is a vector, so simplify.
1 parent 574dbe3 commit 8212034

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -6509,8 +6501,16 @@ SDValue TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG,
65096501
PreShift = PostShift = DAG.getUNDEF(ShSVT);
65106502
MagicFactor = NPQFactor = DAG.getUNDEF(SVT);
65116503
} else {
6504+
6505+
// Try to use leading zeros of the dividend to reduce the multiplier and
6506+
// avoid expensive fixups.
6507+
unsigned LeadingZeros = DAG.computeKnownBits(N0).countMinLeadingZeros();
6508+
// UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros
6509+
// in the dividend exceeds the leading zeros for the divisor.
6510+
LeadingZeros = std::min(LeadingZeros, N1->getAsAPIntVal().countl_zero());
65126511
UnsignedDivisionByConstantInfo magics =
6513-
UnsignedDivisionByConstantInfo::get(Divisor, LeadingZeros);
6512+
UnsignedDivisionByConstantInfo::get(
6513+
Divisor, std::min(KnownLeadingZeros, Divisor.countl_zero()));
65146514

65156515
MagicFactor = DAG.getConstant(magics.Magic, dl, SVT);
65166516

0 commit comments

Comments
 (0)