[llvm] [CombinerHelper]: Use undef for handling divisors of one (PR #91037)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun May 19 23:59:10 PDT 2024
================
@@ -5111,27 +5113,30 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
// Magic algorithm doesn't work for division by 1. We need to emit a select
// 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, std::min(KnownLeadingZeros, Divisor.countl_zero()));
-
- Magic = std::move(magics.Magic);
-
- assert(magics.PreShift < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- assert(magics.PostShift < Divisor.getBitWidth() &&
- "We shouldn't generate an undefined shift!");
- assert((!magics.IsAdd || magics.PreShift == 0) && "Unexpected pre-shift");
- PreShift = magics.PreShift;
- PostShift = magics.PostShift;
- SelNPQ = magics.IsAdd;
+ if (Divisor.isOne()) {
+ PreShifts.push_back(MIB.buildUndef(ScalarShiftAmtTy).getReg(0));
+ MagicFactors.push_back(MIB.buildUndef(ScalarTy).getReg(0));
+ NPQFactors.push_back(MIB.buildUndef(ScalarTy).getReg(0));
+ PostShifts.push_back(MIB.buildUndef(ScalarShiftAmtTy).getReg(0));
----------------
arsenm wrote:
call buildUndef once per type
https://github.com/llvm/llvm-project/pull/91037
More information about the llvm-commits
mailing list