RyuJIT: should always decompose GT_MOD into a - (a / b) * b
for CSE
#32615
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
optimization
Milestone
A % B
can be transformed intoA - ((A / B) * B)
and it's always done for ARM because it doesn't have the remainder instruction.Also for some reason it's done on x64 only when B is a const and a power of two and I suggest we always use what is used for ARM.
It gives VN/CSE more opportunities to find what to optimize, e.g.
can be decomposed into:
then VN/CSE optimizes it to:
So the existing hack in Math.DivRem won't be needed, this pattern when we need both
/
and%
is quite popular, e.g.: MemoryExtensions:Overlapsor here is a jit-diff:
the only thing, lowering should compose it back to
GT_MOD
on x64 if CSE didn't find anything (when op2 is not a constant).I think this optimization should be way easier to implement than the extraction of both values from
idiv
(#5213)@dotnet/jit-contrib
category:cq
theme:optimization
skill-level:intermediate
cost:medium
impact:small
The text was updated successfully, but these errors were encountered: