This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] remove a chain of dead blocks at once
ClosedPublic

Authored by fedor.sergeev on Aug 30 2018, 3:30 PM.

Details

Summary

Recent change to deleteDeadBlocksFromLoop was not enough to
fix all the problems related to dead blocks after nontrivial
unswitching of switches.

We need to delete all the dead blocks that were created during
unswitching, otherwise we will keep having problems with phi's
or dead blocks.

This change removes all the dead blocks that are reachable from the loop,
not trying to track whether these blocks are newly created by unswitching
or not. While not completely correct, we are unlikely to get loose but
reachable dead blocks that do not belong to our loop nest.

It does fix all the failures currently known, in particular PR38778.

Diff Detail

Repository
rL LLVM

Event Timeline

fedor.sergeev created this revision.Aug 30 2018, 3:30 PM

correcting typo

asbirlea added inline comments.Aug 30 2018, 4:31 PM
lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
1387 ↗(On Diff #163434)

Do we need to go over all parent loops now? Processing the successors of each block in DeathCandidates may be enough. It at least resolves testcase delete-dead-blocks.ll which motivated processing blocks in parent loops.

1389 ↗(On Diff #163434)

Could we pull the while outside the for loop?
And populate the initial DeathCandidates with ExitBlocks and loop blocks?

addressing comments:

  • populate candidates with current loop blocks + exit blocks
  • run candidate loop separately after that

Also removed DeadBlocks vector since it duplicates the set
and is not actively used.

fedor.sergeev marked 2 inline comments as done.Aug 31 2018, 2:15 AM
fedor.sergeev edited the summary of this revision. (Show Details)Sep 4 2018, 4:46 AM
asbirlea accepted this revision.Sep 4 2018, 10:04 AM
This revision is now accepted and ready to land.Sep 4 2018, 10:04 AM
This revision was automatically updated to reflect the committed changes.