Skip to content

Commit

Permalink
Check call has one predecessor before considering eliminating guard
Browse files Browse the repository at this point in the history
When applying constraints for a non-overridden call guard,
constrainIfcmpeqne looks at the guarded call node to see whether the
guard can be eliminated.  However, if the call block has more than one
predecessor, not all definitions that reach the call block might have
been visited on the current walk.  That might result in incorrect
constraints being applied to the references on the call because of the
incomplete information.

This change adds an additional check of whether the block containing the
guarded call has only one predecessor before checking whether the guard
can be eliminated.  That is a simple way of ensuring all the
predecessors of the guarded call must already have been walked.

Signed-off-by:  Henry Zongaro <zongaro@ca.ibm.com>
  • Loading branch information
hzongaro committed Jul 21, 2022
1 parent edf2ae5 commit 1b6af95
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/optimizer/VPHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9457,8 +9457,16 @@ static TR::Node *constrainIfcmpeqne(OMR::ValuePropagation *vp, TR::Node *node, b
{
TR::Node *callNode = node->getVirtualCallNodeForGuard();

// In order to decide correctly whether the guard can be eliminated, we need to ensure
// all predecessor blocks of the call block have been walked, and hence all definitions
// used by the call have been considered. The easiest way to do that is to check
// whether the call has only one predecessor - the current block.
// A potential refinement would be to check whether all of the call block's predecessors
// have been walked, and that this is the last predecessor being visited on this walk.
//
if (callNode &&
callNode->getOpCode().isCall())
callNode->getOpCode().isCall() &&
target->getPredecessors().size() == 1)
{
virtualGuardWillBeEliminated = canFoldNonOverriddenGuard(vp, callNode, node);
if (!virtualGuardWillBeEliminated &&
Expand Down

0 comments on commit 1b6af95

Please sign in to comment.