-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
RyuJIT: Optimize test
instruction in case of GT_RELOP(op1=oper that sets flags, op2 = const zero)
#6794
Comments
Why would you limit signed compare to just |
Relop Peep-hole optimization. |
I played a bit with this and it looks like there aren't many opportunities in jitdiff fx:
But it's pretty cheap to implement so maybe one day... |
And because they require the overflow flag the optimization would be incorrect due to integer overflow. Which unfortunately means that this is not so useful and more complicated to implement. The remaining signed LT and GE relops that do work need JS/JNS instructions but we don't currently have a way to represent those in IR. Besides, like all pattern matching the JIT does, this fails to work when the ADD/SUB operations are "hidden" behind a local var. So cases like for (int i = x; i >= 0; i--) { ... } where this optimization would be more useful won't be handled anyway. |
I have a change that implements this in https://github.com/mikedn/coreclr/commits/cmp-flags-2 There are some 70 hits in corelib and a few others in the rest of the framework. As such I'm not sure if it's worth it. cc @sdmaclea |
@mikedn Are you referring to this change mikedn/coreclr@049992a ? Is there a reason you can't leave the comparison ops alone, but use the type of the comparison to adjust the generated code. Seems it would keep the issue restricted to platform codegen. |
That change happens to add support for S and NS condition codes (MI an PL on ARM). The actual optimization is in the subsequent commit.
The comparison is removed, perhaps you're referring to the JCC/SETCC nodes? We could certainly slap another GTF flag on it to indicate that we want S/NS instead of L/GE but personally I don't like using flags for this stuff, it feels like a hack. Anyway, the change in 49992a is something I happen to have around from other experiments (such as if conversion) so I just used that. |
Might be worth looking at this again; was looking if the dec r13d
test r13d, r13d
jl SHORT G_M59263_IG15 On that PR the following change https://github.com/dotnet/coreclr/compare/master...benaadams:peephole-opt-incdec?expand=1 produced
The impact would be larger since it would effecting a generic (i.e. Dictionary) as well as the new Utf8Formatter:TryFormat methods. Don't think my peephole change is correct due to the difference with the overflow flag; and @mikedn's change looks far more comprehensive, |
Although maybe changing the test in the C# will trigger the |
No doesn't seem to work 😢 |
test
instruction in case of GT_RELOP(op1=oper that sets flags, op2 = const zero)
PR dotnet/coreclr#7943 fixed this issue for == and != against zero. Still the following cases can be optimized when op1 is known to set ZF and SF flags.
category:cq
theme:basic-cq
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: