Skip to content

Prevent a SOF in TR_InductionVariableAnalysis::getEntryValue() - #6180

Merged
0xdaryl merged 1 commit into
eclipse-omr:masterfrom
klangman:PR146288
Sep 22, 2021
Merged

0xdaryl merged 1 commit into
eclipse-omr:masterfrom
klangman:PR146288

Conversation

@klangman

Copy link
Copy Markdown
Contributor

In extreme cases the recursion in getEntryValue() can cause a SOF
when compiling large methods. This change will prevent the SOF by
introducing a depth parameter that will prevent the recursion from
exceeding a maximum depth and therefore preventing a SOF condition.

Signed-off-by: Kevin Langman langman@ca.ibm.com

@0xdaryl 0xdaryl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdmpapin did some offline analysis on how this situation could occur. I think it would be useful to surface at least a few sentences of that analysis in this PR to motivate the fix and provide context in where the problem could occur.

TR_PredecessorIterator pit(block);
TR::Node *defValue = (TR::Node *)-1;
for (TR::CFGEdge *edge = pit.getFirst(); edge; edge = pit.getNext())
const int32_t maxDepth=500;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this settable by a environment variable, defaulting to 500?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does "TR_IVAMaxDepth" sound? Maybe you or @jdmpapin can think of a more appropriate env var name?

@jdmpapin jdmpapin Sep 17, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe TR_IVAEntryValueMaxDistance or TR_IVAEntryValueMaxDepth?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TR_IVAEntryValueMaxDistance seems reasonable to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TR_IVAEntryValueMaxDistance seems reasonable to me.

@0xdaryl Oops.. I just saw your comment just after pushing a change to use TR_IVAEntryValueMaxDepth. I'll change it if you think it's worth doing??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I'm fine with what you have.

@jdmpapin

jdmpapin commented Sep 17, 2021 •

Copy link
Copy Markdown
Contributor

getEntryValue() searches backwards for all (possible) definitions of symRef that reach the loop header, and it does so recursively with a recursion depth equal to the length of the (backward) path it is currently exploring (maybe give or take one block, which we can disregard). This means that for each reaching definition of symRef, the recursion depth will grow to be at least the length of the shortest path back to the definition (without going through another possible definition), and depending on the order of predecessors in the CFG, the recursion depth might grow to the length of the longest such path. The only bound we have on this recursion is roughly the number of blocks in the entire method, so it's possible to overflow the stack if a definition reaches from very far before the loop (as measured potentially by the longest path to it, but especially by the shortest)

@jdmpapin

Copy link
Copy Markdown
Contributor

@klangman, you can include my description in the commit message if you like

In extreme cases the recursion in getEntryValue() can cause a SOF
when compiling large methods. This change will prevent the SOF by
introducing a depth parameter that will prevent the recursion from
exceeding a maximum depth and therefore preventing a SOF condition.

Signed-off-by: Kevin Langman <langman@ca.ibm.com>
@0xdaryl

0xdaryl commented Sep 18, 2021

Copy link
Copy Markdown
Contributor

Jenkins build all

@klangman

Copy link
Copy Markdown
Contributor Author

@0xdaryl Everything but RISC-V tests passed.. Maybe that's an unrelated problem that happens without my change?

@0xdaryl 0xdaryl self-assigned this Sep 22, 2021
@0xdaryl

0xdaryl commented Sep 22, 2021

Copy link
Copy Markdown
Contributor

RISC-V timeout is not related to this PR. Merging.

@0xdaryl
0xdaryl merged commit 9494694 into eclipse-omr:master Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants