-
Notifications
You must be signed in to change notification settings - Fork 396
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
Ensure simplifier keeps required DIVCHK operations #7046
Ensure simplifier keeps required DIVCHK operations #7046
Conversation
Devin @jdmpapin, may I ask you to review this change? I have to admit that I'm a little bit uncomfortable with the handshake that exists between the |
In terms of the handshake, I think it would be better to be more explicit. (edit: I mean in the code itself. Your comments are very explicit already!) Here's an idea:
I imagine it would be treated something like the following: the What do you think? |
Thanks for the suggestion, Devin @jdmpapin! Let me play with that. I'll move this pull request back to draft status in the meanwhile. |
f4cc9fe
to
3c7f62f
Compare
Devin @jdmpapin, as you suggested I revised the changes to have the |
Devin @jdmpapin, when you have the opportunity, may I ask you to review the revised changes for this pull request? |
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.
My biggest suggestion is the comment I left in idivSimplifier()
, which I think would significantly simplify the logic and perhaps also eliminate the need to change fold*Constant()
to indicate success. My only reservation is that by not bothering to precisely distinguish the cases where eliminating DIVCHK
is optional vs. mandatory, we'd lose the ability to performTransformation()
in the optional cases. But I'm not sure how concerned to be about that, and if we decide it's important, then I think we could do an earlier performTransformation()
that covers more logic, e.g. something along the lines of
if (divisor != 0 && performTransformation(...))
Thanks for your review, Devin @jdmpapin. I took your suggestion and performed an early call to Once you're OK with these changes, I will squash commits 37c05e2 and 7ebe636. The one comment I've left open is on May I ask you to re-review? |
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.
Thanks for the update! I have a few more comments
Yes, that would be better than bulking up the definition of |
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.
Thanks for all the updates! LGTM, with one small oddity
Awesome, good to squash! |
The divchkSimplifier was first simplifying its child node and then checking whether the DIVCHK is still needed after having simplified its child. It did that by checking whether the simplification of its child results in a node that is not the original child, or the simplified child is not a division or remainder operation. However, it might be that the simplified child is still a division or remainder operation that needs to be checked for division by zero, but is not the original child node. That leads divchkSimplifier to replace the DIVCHK with a treetop operation incorrectly. This change introduces a _nodeToDivchk field in OMR::Simplifier that the integer division and remainder simplifiers use to indicate whether the result of attempting the simplification results in a node that would still need to be checked for division by zero if the original node needed to be checked for division by zero. In most cases that handling of the handshake in the integer division and remainder simplifiers happens in a new function that's called if the divisor is a non-zero constant, permitSimplificationOfConstantDivisor. That function is responsible for checking that the parent of the operation is a DIVCHK, and if so, that performTransformation allows the DIVCHK to be removed. The divchkSimplifier, after simplifying its child division or remainder operation, checks _nodeToDivchk as a first step in determining whether the DIVCHK is still needed. If it is NULL, the DIVCHK is removed; if it is non-NULL, that node is made the subject of the DIVCHK. Also, moved references to BINARY_IDENTITY_OP in the integer division and remainder simplifiers so that it's only used in situations where the divisor is already known to be a constant, so the handshake with the divchkSimplifier will already have been handled by those simplifiers. That avoids having BINARY_IDENTITY_OP deal with the handshake itself. This change also fixes bugs in some simplifiers where division by zero could result from attempting to fold the result of an operation where both operands are constant.
OMR::Optimization::anchorChildren sets hasCommonedAncestor to the result of the comparison of the node's reference count and 1. However, the traceMsg it was emitting claimed that it was always setting hasCommonedAncestor to true, even if the result of the comparison was false. Corrected this to reflect that actual result of the comparison.
f3b666d
to
707ac80
Compare
Thanks for your thorough reviews and the original suggestion on how to handle the handshake, Devin @jdmpapin. I've squashed the commits. |
Jenkins build all |
I think the x86-64 macOS failure is known issue #6516. |
All other tests have passed |
The
divchkSimplifier
was first simplifying its child node and then checking whether theDIVCHK
is still needed after having simplified its child. It did that by checking whether the simplification of its child results in a node that is not the original child, or the simplified child is not a division or remainder operation.However, it might be that the simplified child is still a division or remainder operation that needs to be checked for division by zero, but is not the original child node. The existing logic leads
divchkSimplifier
to replace theDIVCHK
with atreetop
operation incorrectly.This change revises the division and remainder simplifiers so that they only directly replace the child of the parent
DIVCHK
(if any) with a different division or remainder node that must still be checked for division by zero.This pull request also contains a minor change to a trace message in
OMR::Optimization::anchorChildren
.Fixes: eclipse-openj9/openj9#17066