Skip to content

Commit 3012fb6

Browse files
toppercyuxuanchen1997
authored andcommitted
[GlobalISel] Reorder code in CombinerHelper::buildUDivUsingMul. NFC (#99565)
Summary: Group the code for handling Exact udiv together above the code for non-Exact. Move the computeKnownBits call to after the Exact udiv handling. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251104
1 parent 5fda8d0 commit 3012fb6

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5179,13 +5179,9 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
51795179
LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
51805180
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
51815181

5182-
unsigned KnownLeadingZeros =
5183-
KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
51845182
auto &MIB = Builder;
51855183

51865184
bool UseSRL = false;
5187-
bool UseNPQ = false;
5188-
SmallVector<Register, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
51895185
SmallVector<Register, 16> Shifts, Factors;
51905186
auto *RHSDefInstr = cast<GenericMachineInstr>(getDefIgnoringCopies(RHS, MRI));
51915187
bool IsSplat = getIConstantSplatVal(*RHSDefInstr, MRI).has_value();
@@ -5213,6 +5209,33 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
52135209
return true;
52145210
};
52155211

5212+
if (MI.getFlag(MachineInstr::MIFlag::IsExact)) {
5213+
// Collect all magic values from the build vector.
5214+
if (!matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern))
5215+
llvm_unreachable("Expected unary predicate match to succeed");
5216+
5217+
Register Shift, Factor;
5218+
if (Ty.isVector()) {
5219+
Shift = MIB.buildBuildVector(ShiftAmtTy, Shifts).getReg(0);
5220+
Factor = MIB.buildBuildVector(Ty, Factors).getReg(0);
5221+
} else {
5222+
Shift = Shifts[0];
5223+
Factor = Factors[0];
5224+
}
5225+
5226+
Register Res = LHS;
5227+
5228+
if (UseSRL)
5229+
Res = MIB.buildLShr(Ty, Res, Shift, MachineInstr::IsExact).getReg(0);
5230+
5231+
return MIB.buildMul(Ty, Res, Factor);
5232+
}
5233+
5234+
unsigned KnownLeadingZeros =
5235+
KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
5236+
5237+
bool UseNPQ = false;
5238+
SmallVector<Register, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
52165239
auto BuildUDIVPattern = [&](const Constant *C) {
52175240
auto *CI = cast<ConstantInt>(C);
52185241
const APInt &Divisor = CI->getValue();
@@ -5258,29 +5281,6 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
52585281
return true;
52595282
};
52605283

5261-
if (MI.getFlag(MachineInstr::MIFlag::IsExact)) {
5262-
// Collect all magic values from the build vector.
5263-
bool Matched = matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern);
5264-
(void)Matched;
5265-
assert(Matched && "Expected unary predicate match to succeed");
5266-
5267-
Register Shift, Factor;
5268-
if (Ty.isVector()) {
5269-
Shift = MIB.buildBuildVector(ShiftAmtTy, Shifts).getReg(0);
5270-
Factor = MIB.buildBuildVector(Ty, Factors).getReg(0);
5271-
} else {
5272-
Shift = Shifts[0];
5273-
Factor = Factors[0];
5274-
}
5275-
5276-
Register Res = LHS;
5277-
5278-
if (UseSRL)
5279-
Res = MIB.buildLShr(Ty, Res, Shift, MachineInstr::IsExact).getReg(0);
5280-
5281-
return MIB.buildMul(Ty, Res, Factor);
5282-
}
5283-
52845284
// Collect the shifts/magic values from each element.
52855285
bool Matched = matchUnaryPredicate(MRI, RHS, BuildUDIVPattern);
52865286
(void)Matched;

0 commit comments

Comments
 (0)