Skip to content

Commit 787d961

Browse files
committed
[GlobalISel]: Simplify udiv lowering by determining known zeros
1 parent 231beff commit 787d961

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5069,6 +5069,8 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
50695069
const unsigned EltBits = ScalarTy.getScalarSizeInBits();
50705070
LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
50715071
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
5072+
unsigned KnownLeadingZeros =
5073+
KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
50725074
auto &MIB = Builder;
50735075

50745076
bool UseNPQ = false;
@@ -5087,7 +5089,7 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
50875089
// TODO: Use undef values for divisor of 1.
50885090
if (!Divisor.isOne()) {
50895091
UnsignedDivisionByConstantInfo magics =
5090-
UnsignedDivisionByConstantInfo::get(Divisor);
5092+
UnsignedDivisionByConstantInfo::get(Divisor, KnownLeadingZeros);
50915093

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

llvm/test/CodeGen/AArch64/GlobalISel/combine-udiv.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ define i32 @udiv_div_by_180(i32 %x)
257257
;
258258
; GISEL-LABEL: udiv_div_by_180:
259259
; GISEL: // %bb.0:
260-
; GISEL-NEXT: ubfx w8, w0, #2, #6
261-
; GISEL-NEXT: mov w9, #27671 // =0x6c17
262-
; GISEL-NEXT: movk w9, #5825, lsl #16
260+
; GISEL-NEXT: uxtb w8, w0
261+
; GISEL-NEXT: mov w9, #5826 // =0x16c2
262+
; GISEL-NEXT: movk w9, #364, lsl #16
263263
; GISEL-NEXT: umull x8, w8, w9
264-
; GISEL-NEXT: lsr x8, x8, #32
265-
; GISEL-NEXT: lsr w0, w8, #2
264+
; GISEL-NEXT: lsr x0, x8, #32
265+
; GISEL-NEXT: // kill: def $w0 killed $w0 killed $x0
266266
; GISEL-NEXT: ret
267267
{
268268
%truncate = and i32 %x, 255

0 commit comments

Comments
 (0)