This is an archive of the discontinued LLVM Phabricator instance.

[Inline][Cloning] Reliably remove unreachable blocks during cloning (PR53206)
ClosedPublic

Authored by nikic on Jan 28 2022, 3:46 AM.

Details

Summary

The pruning cloner already tries to remove unreachable blocks. The original cloning process will simplify instructions and constant terminators, and only clone blocks that are reachable at that point. However, phi nodes can only be simplified after everything has been cloned. For that reason, additional blocks may become unreachable after phi simplification.

The code does try to handle this as well, but only removes blocks that don't have predecessors. It misses unreachable cycles. This can cause issues if SEH exception handling code is part of an unreachable cycle, as the inliner is not prepared to deal with that.

This patch instead performs an explicit scan for reachable blocks, and drops everything else.

Fixes https://github.com/llvm/llvm-project/issues/53206.

Diff Detail

Event Timeline

nikic created this revision.Jan 28 2022, 3:46 AM
nikic requested review of this revision.Jan 28 2022, 3:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2022, 3:46 AM

Have you considered using removeUnreachableBlocks()?

nikic added a comment.Jan 28 2022, 4:04 AM

Have you considered using removeUnreachableBlocks()?

I did consider that, but the implementation seems to be doing significantly more than just removing unreachable blocks, and I was not entirely certain that it is appropriate here.

If desired, I can switch to that though (with an interface change to accept a start block rather than a function).

rnk accepted this revision.Jan 28 2022, 10:04 AM

removeUnreachableBlocks operates on the whole function and preserves extra analyses. I think it makes sense to have a mini-DFS here to consider only a single inlined function body.

lgtm

This revision is now accepted and ready to land.Jan 28 2022, 10:04 AM
This revision was landed with ongoing or failed builds.Jan 31 2022, 12:33 AM
This revision was automatically updated to reflect the committed changes.