diff options
| author | AtariDreams <gfunni234@gmail.com> | 2024-04-24 16:14:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-24 22:14:02 +0200 |
| commit | 13188bcd9f748dee13cf848340833f6eec2d90d4 (patch) | |
| tree | ae3ecfafadb4f2fec23079ac4da3b6aad91a9437 /llvm/lib/CodeGen | |
| parent | c5dcb5239e5a3ee68155ba2d09d1fa37ca512cd7 (diff) | |
| download | llvm-13188bcd9f748dee13cf848340833f6eec2d90d4.tar.gz llvm-13188bcd9f748dee13cf848340833f6eec2d90d4.tar.bz2 llvm-13188bcd9f748dee13cf848340833f6eec2d90d4.zip | |
[GlobalISel]: Simplify udiv lowering by determining known zeros (#89678)
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index 050f42e9039b..653e7689b577 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -5069,6 +5069,9 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) { const unsigned EltBits = ScalarTy.getScalarSizeInBits(); LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty); LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType(); + + unsigned KnownLeadingZeros = + KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0; auto &MIB = Builder; bool UseNPQ = false; @@ -5086,8 +5089,12 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) { // at the end. // TODO: Use undef values for divisor of 1. if (!Divisor.isOne()) { + + // UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros + // in the dividend exceeds the leading zeros for the divisor. UnsignedDivisionByConstantInfo magics = - UnsignedDivisionByConstantInfo::get(Divisor); + UnsignedDivisionByConstantInfo::get( + Divisor, std::min(KnownLeadingZeros, Divisor.countl_zero())); Magic = std::move(magics.Magic); |
