Skip to content

Commit ab1be92

Browse files
committed
[CodeGen] Remove redundant checks
It turns out we can safely use DAG.computeKnownBits(N0).countMinLeadingZeros() with constant legal vectors, so remove the check for it.
1 parent 5e8cd29 commit ab1be92

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5180,7 +5180,9 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
51805180
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
51815181

51825182
unsigned KnownLeadingZeros =
5183-
KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
5183+
(!MI.getFlag(MachineInstr::MIFlag::IsExact) && KB)
5184+
? KB->getKnownBits(LHS).countMinLeadingZeros()
5185+
: 0;
51845186
auto &MIB = Builder;
51855187

51865188
bool UseSRL = false;

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 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;
@@ -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

Comments
 (0)