File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
test/CodeGen/AArch64/GlobalISel Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -5069,6 +5069,14 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
5069
5069
const unsigned EltBits = ScalarTy.getScalarSizeInBits ();
5070
5070
LLT ShiftAmtTy = getTargetLowering ().getPreferredShiftAmountTy (Ty);
5071
5071
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType ();
5072
+
5073
+ // UnsignedDivisionByConstantInfo doesn't work correctly if leading zeros in
5074
+ // the dividend exceeds the leading zeros for the divisor.
5075
+ unsigned KnownLeadingZeros =
5076
+ KB ? std::min (KB->getKnownBits (LHS).countMinLeadingZeros (),
5077
+ KB->getKnownBits (RHS).countMinLeadingZeros ())
5078
+ : 0 ;
5079
+
5072
5080
auto &MIB = Builder;
5073
5081
5074
5082
bool UseNPQ = false ;
@@ -5087,7 +5095,7 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
5087
5095
// TODO: Use undef values for divisor of 1.
5088
5096
if (!Divisor.isOne ()) {
5089
5097
UnsignedDivisionByConstantInfo magics =
5090
- UnsignedDivisionByConstantInfo::get (Divisor);
5098
+ UnsignedDivisionByConstantInfo::get (Divisor, KnownLeadingZeros );
5091
5099
5092
5100
Magic = std::move (magics.Magic );
5093
5101
Original file line number Diff line number Diff line change @@ -257,12 +257,12 @@ define i32 @udiv_div_by_180(i32 %x)
257
257
;
258
258
; GISEL-LABEL: udiv_div_by_180:
259
259
; 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
263
263
; 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
266
266
; GISEL-NEXT: ret
267
267
{
268
268
%truncate = and i32 %x , 255
You can’t perform that action at this time.
0 commit comments