-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[arm64] Disable a % b = a & (b - 1);
optimization.
#18206
Conversation
It was copied wrong previously.
Morph can't relay on Lower optimization that it can't guarantee.
a % b = a & (b - 1);
optimization on arm64a % b = a & (b - 1);
optimization.
@dotnet-bot test Windows_NT x64_arm64_altjit Checked r2r_jitstress1 |
The reason why Lower doesn't do anything in this case is somewhat artificial. I expected that constant folding would handle such cases so that there's no reason to reproduce that logic in lowering. But there's nothing stopping lowering from doing it and it's IMO its responsibility to produce IR suitable for the target CPU. In the particular case of
That seems unrelated since |
I agree that we should decide to do an optimization and do the optimization in one place.
We do not transform |
@mmitche Looks like ci is down, do you know about this problem? |
Yes, this is a funny situation. On ARM we don't have much of a choice since there is not On x86/x64 the transform is not required and if we do it for the sake of CSE we end up with an extra
I suppose CSE could try to look for an available And there's also the x86/64 specific case that if you have both |
@dotnet-bot test this please |
We do not expect MOD/UMOD for integer/long types in lower for arm64.
@dotnet-bot test Windows_NT x64_arm64_altjit Checked r2r |
#ifdef _TARGET_XARCH_ | ||
if (!varTypeIsFloating(node->TypeGet())) | ||
#endif // _TARGET_XARCH_ | ||
if (varTypeIsIntegral(node->TypeGet())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CarolEidt could you please take a look at this check? Do you remember why it was _TARGET_XARCH_
specific before?
LowerConstIntDivOrMod
has assert((type == TYP_INT) || (type == TYP_LONG));
, so looks like it is not correct to skip this check for arm/arm64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ifdef was probably intended to include the entire if, not just the condition. I don't think I enabled magic division for ARM64 when I wrote the code, it didn't have GT_MULHI
back then. I see that now it's enabled for ARM64 but it's still not enabled for ARM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not enabled for arm because we do not allow integer MOD/DIV in Lower on this platform.
So, I do not see a reason why we need this target ifdef
now, it works fine for XARCH DIV/MOD and for arm64 DIV nodes (MOD are not allowed in Lower).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason why it should be target-specific either.
PTAL @dotnet/jit-contrib, @dotnet/arm64-contrib |
#ifdef _TARGET_XARCH_ | ||
if (!varTypeIsFloating(node->TypeGet())) | ||
#endif // _TARGET_XARCH_ | ||
if (varTypeIsIntegral(node->TypeGet())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason why it should be target-specific either.
Failures are not related with this change. |
@sandreenko Can you also re-enable it in issues.targets:
|
Thanks, that was missed, I will publish the PR shortly. |
Morph can't relay on Lower optimization that it can't guarantee.
In this test case we have such tree:
Moprh thinks that Lower will optimize it as
a % b = a & (b - 1);
, but thena
tree is found to be a constant:and Lower rejects optimizing
a % b
when both operands are const.It cases assert during Lsra:
assert(!"Shouldn't see an integer typed GT_MOD node in ARM64");
The fix is similar to #17338.
Fixes #17968.
PR #15690 can help to return this optimization back.