Skip to content

Commit cbb8f91

Browse files
committed
Prevent improper removal of static store in idiom recognition
Previously, a static store could be marked negligible based on its uses in TR_CISCTransformer::simpleOptimization(), which could allow for the loop to be transformed in a way that removes the store. Issue: #15319
1 parent 64f6135 commit cbb8f91

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

runtime/compiler/optimizer/IdiomRecognition.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,28 @@ TR_CISCGraph::importUDchains(TR::Compilation *comp, TR_UseDefInfo *useDefInfo, b
15271527
/* set DU-chains to TR_CISCNode._chain */
15281528
TR_ASSERT(n->getTrNodeInfo()->isSingleton(), "direct store must correspond to a single TR node");
15291529
TR::Node *trNode = n->getTrNodeInfo()->getListHead()->getData()->_node;
1530+
1531+
if (!trNode->getSymbol()->isAutoOrParm())
1532+
{
1533+
TR_ASSERT_FATAL_WITH_NODE(
1534+
trNode,
1535+
trNode->getSymbol()->isStatic(),
1536+
"direct store to non-auto, non-static");
1537+
1538+
// Regardless of the uses that we can see within this method (which
1539+
// may not even appear, since we won't necessarily get use-def
1540+
// indices for static accesses), it's always possible that the
1541+
// destination static is used after the loop, but outside of this
1542+
// method. Recognizing this possibility will prevent the store from
1543+
// being considered negligible and ultimately incorrectly removed.
1544+
n->addChain(_exitNode, true);
1545+
1546+
// With this use recorded here, any real uses that might happen to
1547+
// be available are no longer informative. Avoid adding a duplicate
1548+
// entry for _exitNode.
1549+
continue;
1550+
}
1551+
15301552
int32_t useDefIndex = trNode->getUseDefIndex();
15311553
if (useDefIndex == 0) continue;
15321554
TR_ASSERT(useDefInfo->isDefIndex(useDefIndex), "error!");

0 commit comments

Comments
 (0)