Skip to content

Conversation

@jakobbotsch
Copy link
Member

I spent some time today figuring out why we have these additional (and seemingly unnecessary) successors when iterating EH successors, and found these two reasons.

I spent some time today figuring out why we have these additional (and
seemingly unnecessary) successors when iterating EH successors, and
found these two reasons.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 11, 2023
@ghost ghost assigned jakobbotsch Nov 11, 2023
@ghost
Copy link

ghost commented Nov 11, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

I spent some time today figuring out why we have these additional (and seemingly unnecessary) successors when iterating EH successors, and found these two reasons.

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

Comment on lines +567 to +573
// * It simplifies PHI arguments in handlers. In particular, when control is
// transferred to a handler, the reaching defs of live-in locals may come
// from predecessors of the try block if an exception was thrown before a def
// in the try. Without considering these as preds, we would have odd phi args
// (referring to blocks that aren't considered to be predecessors), or we
// would need to insert extra PHI definitions in the try block that the
// handler could refer to.
Copy link
Member Author

Choose a reason for hiding this comment

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

To be completely honest I think this alternative way of modelling things (adding "degenerate" phis at the entry try block) would be slightly more elegant.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting.

Along those lines we could require the first (real) statement of the try be some sort of fake def -- GT_ENTERTRY? It would mess up some other things like empty block detection and try removal, but I expect we can fix those things.

That in turn might make it easier to allow trys with arbitrary or multiple entry points, since (perhaps) we'd no longer have to guarantee that the lexical try entry dominated all the blocks in the try. Each entry would just need one of these special statements...

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I don't think we need the degenerate phis... it is clearly not an uncommon scenario for a reaching def to be from some other block than the pred. So what I call out to be "odd" here is not actually odd.

As it turns out we already process the try heads specially, so I don't think my second reason described here exists. And it seems simple to generalize it to handle your case, we just need to generalize the following check to not be restricted to the head try block:

if (m_pCompiler->bbIsTryBeg(succ))

So that only leaves the dominator tree computation, as far as I can tell... seems like it would be more reasonable to handle it specially there instead of overapproximating the EH successor/predecessor sets for everyone. I'll probably give this a try and see if I hit any other snags.

@jakobbotsch
Copy link
Member Author

Superseded by #94672

@jakobbotsch jakobbotsch deleted the successor-eh-successors branch November 13, 2023 19:46
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants