Skip to content

Commit

Permalink
[GlobalISel]: Simplify udiv lowering by determining known zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
AtariDreams committed Apr 23, 2024
1 parent 231beff commit 787d961
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5069,6 +5069,8 @@ 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;
Expand All @@ -5087,7 +5089,7 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
// TODO: Use undef values for divisor of 1.
if (!Divisor.isOne()) {
UnsignedDivisionByConstantInfo magics =
UnsignedDivisionByConstantInfo::get(Divisor);
UnsignedDivisionByConstantInfo::get(Divisor, KnownLeadingZeros);

Magic = std::move(magics.Magic);

Expand Down
10 changes: 5 additions & 5 deletions llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.ll
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ define i32 @udiv_div_by_180(i32 %x)
;
; GISEL-LABEL: udiv_div_by_180:
; GISEL: // %bb.0:
; GISEL-NEXT: ubfx w8, w0, #2, #6
; GISEL-NEXT: mov w9, #27671 // =0x6c17
; GISEL-NEXT: movk w9, #5825, lsl #16
; GISEL-NEXT: uxtb w8, w0
; GISEL-NEXT: mov w9, #5826 // =0x16c2
; GISEL-NEXT: movk w9, #364, lsl #16
; GISEL-NEXT: umull x8, w8, w9
; GISEL-NEXT: lsr x8, x8, #32
; GISEL-NEXT: lsr w0, w8, #2
; GISEL-NEXT: lsr x0, x8, #32
; GISEL-NEXT: // kill: def $w0 killed $w0 killed $x0
; GISEL-NEXT: ret
{
%truncate = and i32 %x, 255
Expand Down

0 comments on commit 787d961

Please sign in to comment.