This is an archive of the discontinued LLVM Phabricator instance.

[BranchFolding] Allow hoisting to block with a single conditional branch.
ClosedPublic

Authored by gberry on May 1 2018, 11:07 AM.

Details

Summary

The BranchFolding pass is currently missing opportunities to hoist
common code if the hoisted-to block contains a single conditional branch
that has register uses. This occurs somewhat frequently on AArch64 with
CBZ/TBZ opcodes.

This change also eliminates some code differences when debug info is
present since the presence of e.g. DBG_VALUE instructions in the
hoisted-to block can enable hoisting that wouldn't have occurred without
them.

Diff Detail

Repository
rL LLVM

Event Timeline

gberry created this revision.May 1 2018, 11:07 AM
aprantl added inline comments.May 11 2018, 8:53 AM
lib/CodeGen/BranchFolding.cpp
1869 ↗(On Diff #144754)

Can you add a comment explaining what this condition checks for and why return Loc is appropriate here?

gberry updated this revision to Diff 146376.May 11 2018, 11:47 AM

Add some comments

kparzysz accepted this revision.May 12 2018, 7:04 AM

Looks ok to me.

This revision is now accepted and ready to land.May 12 2018, 7:04 AM

One thought I had was: if there is a block with only an unconditional branch, should we fold it away first? That is, redirect any branches to that block to the target of the branch?

One thought I had was: if there is a block with only an unconditional branch, should we fold it away first? That is, redirect any branches to that block to the target of the branch?

I believe that should have already been taken care of (see OptimizeBlock() around line 1659). In the case that is being fixed by this patch the block contains just a *conditional* branch.

Alright then. LGTM.

This revision was automatically updated to reflect the committed changes.