[llvm] [GlobalISel] Handle div-by-pow2 (PR #83155)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 02:14:55 PDT 2024
================
@@ -5268,6 +5268,146 @@ MachineInstr *CombinerHelper::buildSDivUsingMul(MachineInstr &MI) {
return MIB.buildMul(Ty, Res, Factor);
}
+bool CombinerHelper::matchDivByPow2(MachineInstr &MI, bool IsSigned) {
+ assert((MI.getOpcode() == TargetOpcode::G_SDIV ||
+ MI.getOpcode() == TargetOpcode::G_UDIV) &&
+ "Expected SDIV or UDIV");
+ auto &Div = cast<GenericMachineInstr>(MI);
+ Register RHS = Div.getReg(2);
+ auto MatchPow2 = [&](const Constant *C) {
+ auto *CI = cast<ConstantInt>(C);
----------------
arsenm wrote:
Actually, you need to defend against null (which is passed for implicit_def, I guess). It doesn't happen now, but in principle matchUnaryPredicate could also pass in the FPImm
https://github.com/llvm/llvm-project/pull/83155
More information about the llvm-commits
mailing list