This is an archive of the discontinued LLVM Phabricator instance.

llvm-reduce: add a pass for cleaning up branches
Needs ReviewPublic

Authored by regehr on Aug 4 2022, 2:31 PM.

Details

Reviewers
aeubanks
arsenm
Summary
I'm doing a lot of reductions starting with full-sized IR modules,
trying to find minimal triggers for random issues detected by alive2.
Even after llvm-reduce reaches a fixpoint, there's often some
control-flow-related junk, often towards the end of the module, that
isn't getting cleaned up by existing passes that we have.

This patch adds three reduction passes. The first one tries to make
every conditional branch into an unconditional branch to the original
branch's true target. The second pass does the same thing, but uses the
false target. The third pass targets unconditional branches. For a BB
terminated by an unconditional branch, all instructions in the BB are
sunk to the start of the successor block and all branches targeting
the original block are pointed to the successor. Then we delete the
block.

On a collection of 53 IR files that I'm using to benchmark
llvm-reduce, this patch changes the average final file size from 710
bytes to 615 bytes, about a 15% improvement.

Diff Detail

Event Timeline

regehr created this revision.Aug 4 2022, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:31 PM
Herald added a subscriber: mgorny. · View Herald Transcript
regehr requested review of this revision.Aug 4 2022, 2:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:31 PM
arsenm added inline comments.Aug 4 2022, 2:33 PM
llvm/tools/llvm-reduce/deltas/ReduceBranches.cpp
25–33

I was looking at doing this by calling simplifyCFG on each block rather than reimplementing the transform

regehr added inline comments.Aug 4 2022, 2:42 PM
llvm/tools/llvm-reduce/deltas/ReduceBranches.cpp
25–33

since the code here is pretty short and simple, how about we just add that onto what I've done here?

none of the transforms here is strictly subsumed by anything in simplifyCFG because that pass has to be semantics-preserving, whereas none of these three are

arsenm added inline comments.Aug 4 2022, 4:12 PM
llvm/tools/llvm-reduce/deltas/ReduceBranches.cpp
73

Do you need to call replaceSuccessorsPhiUsesWith or replacePhiUsesWith to avoid breaking those?

regehr added inline comments.Aug 4 2022, 4:15 PM
llvm/tools/llvm-reduce/deltas/ReduceBranches.cpp
73

let me look into it, thanks.

overall I'm not impressed with the elegance of the code in this function, all suggestions appreciated.