Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
New fix in IsTreeVNInvariant(GenTree* tree)
Browse files Browse the repository at this point in the history
// Don't allow the hoisting of GT_CLS_VAR an GT_LCL_VAR that were assigned a constant value.
  • Loading branch information
briansull committed Sep 17, 2019
1 parent 49380f9 commit d0fdc25
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6789,22 +6789,24 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack<BasicBlock*>* blo
return false;
}

// Don't hoist constants or nodes that have been assigned a constant value.
// Performing such an operation is incorrect as the node being hoisted could be
// moved before the assignment that makes it a constant.
if (m_compiler->vnStore->IsVNConstant(node->gtVNPair.GetLiberal()))
{
return false;
}

// Tree must be a suitable CSE candidate for us to be able to hoist it.
return m_compiler->optIsCSEcandidate(node);
}

bool IsTreeVNInvariant(GenTree* tree)
{
return m_compiler->optVNIsLoopInvariant(tree->gtVNPair.GetLiberal(), m_loopNum,
&m_hoistContext->m_curLoopVnInvariantCache);
ValueNum vn = tree->gtVNPair.GetLiberal();

if (m_compiler->vnStore->IsVNConstant(vn))
{
// Don't allow the hoisting of GT_CLS_VAR an GT_LCL_VAR that were assigned a constant value.
// But allow constant GT_ARGPLACE nodes which occur when we have constant args.
if (!tree->OperIsConst() && tree->OperGet() != GT_ARGPLACE)
{
return false;
}
}
return m_compiler->optVNIsLoopInvariant(vn, m_loopNum, &m_hoistContext->m_curLoopVnInvariantCache);
}

public:
Expand Down

0 comments on commit d0fdc25

Please sign in to comment.