This is an archive of the discontinued LLVM Phabricator instance.

[Dominators] Make RemoveUnreachableBlocks return false if the BasicBlock is already awaiting deletion
ClosedPublic

Authored by NutshellySima on Jul 24 2018, 8:31 AM.

Details

Summary

Previously, removeUnreachableBlocks still returns true (which indicates the CFG is changed) even when all the unreachable blocks found is awaiting deletion in the DDT class.
This makes code pattern like

// Code modified from lib/Transforms/Scalar/SimplifyCFGPass.cpp 
bool EverChanged = removeUnreachableBlocks(F, nullptr, DDT);
...
do {
    EverChanged = someMightHappenModifications();
    EverChanged |= removeUnreachableBlocks(F, nullptr, DDT);
  } while (EverChanged);

become a dead loop.
Fix this by detecting whether a BasicBlock is already awaiting deletion.

Diff Detail

Repository
rL LLVM

Event Timeline

NutshellySima created this revision.Jul 24 2018, 8:31 AM
kuhar added a comment.Aug 2 2018, 8:36 AM

Looks fine except for the test IR.

unittests/Transforms/Utils/Local.cpp
846 ↗(On Diff #158691)

I don't think it's valid to branch to entry (the entry block is supposed to have no predecessors).

Address comments.

NutshellySima marked an inline comment as done.Aug 2 2018, 8:57 AM
kuhar accepted this revision.Aug 2 2018, 9:40 AM
This revision is now accepted and ready to land.Aug 2 2018, 9:40 AM
brzycki accepted this revision.Aug 2 2018, 10:33 AM

OK by me. Probably won't save much compile time but it is a bit cleaner to read.

This revision was automatically updated to reflect the committed changes.