LoopDeletion and use in unreachable block

Hello All,

I filed a bug https://bugs.llvm.org/show_bug.cgi?id=35884 which I want to fix but I’m in trouble with detecting who is wrong :slight_smile:

The story is as follows:

LoopDeletion tries to delete an invariant loop which has a def with use in some unreachable block.

The IR is well-formed due to any use in unreachable block is dominated as Verifier states.

LoopDeletion detected the loop as invariant due to LCSSA builder did not create a Phi node for this def because this def is in

block which does not dominate exit.

When BB with def is destroyed the destroying of def instruction causes an assert due to it has use.

So I wonder who is wrong here:

  1. LCSSA which did not create a Phi node

  2. LoopDeletion which did not take into account that instruction can be used in unreachable block and used a bulk deletion.

Any help is appreciated.

Thank you,


[ +CC Davide, who’s been fixing these unreachable block bugs]

Hi Serguei,

I think loop deletion needs to be fixed here.

For LCSSA verification in `isBlockInLCSSAForm`, we specifically ignore uses in blocks that are not reachable from entry.
We do not need phis for such uses.

So, a loop can be in LCSSA form and still have unreachable uses for def’s and not have phis for those defs.

Although loop deletion uses a reasonable (and AFAICT correct) logic for identifying “invariant” loops by depending on the fact that LCSSA is preserved.
it needs to take into account unreachable uses before deleting that invariant loop.