Skip to content

Commit

Permalink
Ensure DIVCHK and division/remainder simplifiers uphold contract
Browse files Browse the repository at this point in the history
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.

The divchkSimplifier, after simplifying its child division or remainder
operation, checks _nodeToDivchk as a first step in determining whether
the DIVCHK is still needed.

This change also updates the fold*Constant methods to return true to
indicate that they were able to perform the requested transformations,
which are guarded by calls to performTransformation, or return false if
they were unable to.
  • Loading branch information
hzongaro committed Aug 20, 2023
1 parent ac8ca57 commit 7ebe636
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 101 deletions.
2 changes: 2 additions & 0 deletions compiler/optimizer/OMRSimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ OMR::Simplifier::Simplifier(TR::OptimizationManager *manager)
_reassociate = comp()->getOption(TR_EnableReassociation);

_containingStructure = NULL;

_nodeToDivchk = NULL;
}

TR::Optimization *OMR::Simplifier::create(TR::OptimizationManager *manager)
Expand Down
9 changes: 9 additions & 0 deletions compiler/optimizer/OMRSimplifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ class Simplifier : public TR::Optimization
TR::TreeTop *_performLowerTreeSimplifier;
TR::Node *_performLowerTreeNode;
TR::list<std::pair<TR::TreeTop*, TR::Node*> > _performLowerTreeNodePairs;

/**
* This field is used as part of a handshake between the \ref divchkSimplifier
* and the integer division and remainder simplifiers. If simplifying the
* child of a \c DIVCHK leaves us with a node that still must have a \c DIVCHK
* applied, the division or remainder simplifier will set this field to refer
* to that node; otherwise, it will set this field is set to \c NULL.
*/
TR::Node *_nodeToDivchk;
};

}
Expand Down
Loading

0 comments on commit 7ebe636

Please sign in to comment.