This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Relax restriction for folding unconditional branches
ClosedPublic

Authored by skatkov on Jan 30 2018, 7:14 AM.

Details

Summary

The commit rL308422 introduces a restriction for folding unconditional
branches. Specifically if empty block with unconditional branch leads to
header of the loop then elimination of this basic block is prohibited.
However it seems this condition is redundantly strict.
If elimination of this basic block does not introduce more back edges
then we can eliminate this block.

The patch implements this relax of restriction.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Jan 30 2018, 7:14 AM
pacxx accepted this revision.Feb 2 2018, 3:16 AM

LGTM

This revision is now accepted and ready to land.Feb 2 2018, 3:16 AM
efriedma added inline comments.
lib/Transforms/Utils/SimplifyCFG.cpp
5740 ↗(On Diff #131967)

getSinglePredecessor()?

test/Transforms/SimplifyCFG/UncondBranchToHeader.ll
16 ↗(On Diff #131967)

Do we really need SimplifyCFG to rotate loops? We have a dedicated LoopRotate pass for this sort of transform.

But I guess it's okay.

skatkov added inline comments.Feb 4 2018, 8:19 PM
lib/Transforms/Utils/SimplifyCFG.cpp
5740 ↗(On Diff #131967)

make sense.

test/Transforms/SimplifyCFG/UncondBranchToHeader.ll
16 ↗(On Diff #131967)

Hi Eli, I did not follow what you mean here as rotate loop?

Header will be the same. In this particular case the loop will just consists from one basic block header after transformation...

skatkov added inline comments.Feb 4 2018, 8:25 PM
test/Transforms/SimplifyCFG/UncondBranchToHeader.ll
16 ↗(On Diff #131967)

Or you mean that before it was not bottom formed loop and now it is?

This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.Feb 5 2018, 12:09 PM
test/Transforms/SimplifyCFG/UncondBranchToHeader.ll
16 ↗(On Diff #131967)

I don't think I've ever seen the term "bottom formed loop", but yes, that's what I meant.