-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[GlobalISel] Reorder code in CombinerHelper::buildUDivUsingMul. NFC #99565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Groupd the code for handling Exact udiv together above the code for for non-Exact. Move the computeKnownBits call to after the Exact udiv handling.
@llvm/pr-subscribers-llvm-globalisel Author: Craig Topper (topperc) ChangesGroupd the code for handling Exact udiv together above the code for for non-Exact. Move the computeKnownBits call to after the Exact udiv handling. Alternative to #99560 CC: @AtariDreams Full diff: https://github.com/llvm/llvm-project/pull/99565.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index dfc3d73e322b8..d1ce780627268 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -5179,13 +5179,9 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
LLT ScalarShiftAmtTy = ShiftAmtTy.getScalarType();
- unsigned KnownLeadingZeros =
- KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
auto &MIB = Builder;
bool UseSRL = false;
- bool UseNPQ = false;
- SmallVector<Register, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
SmallVector<Register, 16> Shifts, Factors;
auto *RHSDefInstr = cast<GenericMachineInstr>(getDefIgnoringCopies(RHS, MRI));
bool IsSplat = getIConstantSplatVal(*RHSDefInstr, MRI).has_value();
@@ -5213,6 +5209,34 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
return true;
};
+ if (MI.getFlag(MachineInstr::MIFlag::IsExact)) {
+ // Collect all magic values from the build vector.
+ bool Matched = matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern);
+ (void)Matched;
+ assert(Matched && "Expected unary predicate match to succeed");
+
+ Register Shift, Factor;
+ if (Ty.isVector()) {
+ Shift = MIB.buildBuildVector(ShiftAmtTy, Shifts).getReg(0);
+ Factor = MIB.buildBuildVector(Ty, Factors).getReg(0);
+ } else {
+ Shift = Shifts[0];
+ Factor = Factors[0];
+ }
+
+ Register Res = LHS;
+
+ if (UseSRL)
+ Res = MIB.buildLShr(Ty, Res, Shift, MachineInstr::IsExact).getReg(0);
+
+ return MIB.buildMul(Ty, Res, Factor);
+ }
+
+ unsigned KnownLeadingZeros =
+ KB ? KB->getKnownBits(LHS).countMinLeadingZeros() : 0;
+
+ bool UseNPQ = false;
+ SmallVector<Register, 16> PreShifts, PostShifts, MagicFactors, NPQFactors;
auto BuildUDIVPattern = [&](const Constant *C) {
auto *CI = cast<ConstantInt>(C);
const APInt &Divisor = CI->getValue();
@@ -5258,29 +5282,6 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {
return true;
};
- if (MI.getFlag(MachineInstr::MIFlag::IsExact)) {
- // Collect all magic values from the build vector.
- bool Matched = matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern);
- (void)Matched;
- assert(Matched && "Expected unary predicate match to succeed");
-
- Register Shift, Factor;
- if (Ty.isVector()) {
- Shift = MIB.buildBuildVector(ShiftAmtTy, Shifts).getReg(0);
- Factor = MIB.buildBuildVector(Ty, Factors).getReg(0);
- } else {
- Shift = Shifts[0];
- Factor = Factors[0];
- }
-
- Register Res = LHS;
-
- if (UseSRL)
- Res = MIB.buildLShr(Ty, Res, Shift, MachineInstr::IsExact).getReg(0);
-
- return MIB.buildMul(Ty, Res, Factor);
- }
-
// Collect the shifts/magic values from each element.
bool Matched = matchUnaryPredicate(MRI, RHS, BuildUDIVPattern);
(void)Matched;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
bool Matched = matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern); | ||
(void)Matched; | ||
assert(Matched && "Expected unary predicate match to succeed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool Matched = matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern); | |
(void)Matched; | |
assert(Matched && "Expected unary predicate match to succeed"); | |
if (!matchUnaryPredicate(MRI, RHS, BuildExactUDIVPattern)) | |
llvm_unreachable("Expected unary predicate match to succeed"); |
…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
Groupd the code for handling Exact udiv together above the code for for non-Exact. Move the computeKnownBits call to after the Exact udiv handling.
Alternative to #99560
CC: @AtariDreams