[llvm] [InstCombine] Avoid unprofitable add with remainder transform (PR #147319)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 7 12:55:59 PDT 2025
nikic wrote:
> If C1 is 1, this will end up replacing the remainder with a multiply and a longer dependency chain. This is clearly unprofitable in the case where the remainder is an `and`, but I think the profitability is also questionable for `urem` (because usually udiv and urem are produced by the same instruction), so I've disabled both cases.
I've added a special case where the divisor is 2, as that gets beneficial followup folds.
On further consideration, I think it probably generally makes sense to do the transform for the cases using actual div/rem. For constant divisors we're not going to use actual divrem instructions anyway, and after playing around with codegen for different cases a bit, I think the mul ends up being marginally better in most cases.
https://github.com/llvm/llvm-project/pull/147319
More information about the llvm-commits
mailing list