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 doesn't hoist invariant division by non power of 2 constant #4726
Comments
Looks like this doesn't work due to a GT_ASG that's present in the division tree. That's how the shift got CSEd but the rest of tree wasn't. |
Also, because this optimization is done only during global morph cases that rely on constant propagation to have been performed are not handled: static int Test(int x)
{
int y = 3;
return x / y;
} generates:
PS: |
This happens because |
When 2 shifts are needed the currently generated code is less than ideal. The second shift depends on the first shift:
The second shift is simply extracting the sign bit and the previous shift doesn't change the sign bit. So, we could generate this instead:
Saves a |
generates
It also does only partial CSE:
generates
CSE works fine in JIT32 which doesn't do reciprocal multiplication. Both CSE and hoisting work fine in RyuJIT for division by power of 2.
Shouldn't reciprocal multiplication have been done in lowering instead of morphing? The generated IR is larger and more likely to hinder further optimization rather than exposing new optimization opportunities.
The text was updated successfully, but these errors were encountered: