This is an archive of the discontinued LLVM Phabricator instance.

Fix MSSA update in MergeBlockIntoPredecessor
Needs ReviewPublic

Authored by apilipenko on Sep 27 2019, 4:34 PM.

Details

Summary

There are a couple of issues around MergeBlockIntoPredecessor and MSSA update.

Both issues show up when loop-simplify-cfg is used after simple-loop-unswitch.

  1. moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start) expects to be called after all instructions from From were moved to To. Specifically, it assumes that Start belongs to To basic block and iterates over make_range(Start->getIterator(), To->end()) range (see moveAllAccesses). MergeBlockIntoPredecessor currently calls moveAllAfterMergeBlocks before instructions are moved into To and passes Start which belongs to From.

The fix is to call moveAllAfterMergeBlocks after the instructions are moved from From to To.

  1. After simple-loop-unswitch some blocks might end up with trivial phis with one incoming value. When such a block is merged with its predecessor (by loop-simplify-cfg) the phi node is left intact after the block is removed. This results in a dangling reference to a phi without a block. unswitch_simplify_mssa_update.ll test case fails with VerifyMemorySSA && EXPENSIVE_CHECKS on this assertion in verifyPrevDefInPhis: assert(LastAcc == IncAcc && "Incorrect incoming access into phi.");

I fixed this by calling tryRemoveTrivialPhi for From block in moveAllAfterMergeBlocks. I'm not certain that this is the right approach. May be we shouldn't have trivial phis to begin with? Please advise.

Diff Detail

Event Timeline

apilipenko created this revision.Sep 27 2019, 4:34 PM

I'm seeing the attached test pass at ToT now.
I may have resolved it in rL373380, which was failing to remove trivial Phis when inserting a backedge block.
Please let me know if you are still seeing issues!

asbirlea removed a subscriber: asbirlea.May 7 2020, 1:53 PM