This is an archive of the discontinued LLVM Phabricator instance.

[llvm-reduce] optionally keep running delta passes until they stop making the IR smaller
ClosedPublic

Authored by regehr on Jan 8 2022, 2:21 PM.

Details

Summary

Currently, llvm-reduce runs each of its delta passes once, in a fixed order, and then exits. This is a reasonable default behavior since it allows llvm-reduce to run fairly quickly, but it fails to account for the case where a pass later in the phase ordering creates opportunities for a pass earlier in the phase ordering to make more progress.

This patch does not change the default behavior of llvm-reduce, but adds a command line parameter "max-pass-iterations" that specifies the largest number of times that the requested set of delta passes will be run. It also adds logic to bail out of the top-level reduction loop as soon as running the entire collection of passes fails to make the IR module smaller.

I have a small collection of test inputs to llvm-reduce, the average size before reduction is 15 KB. After reduction by the current llvm-reduce, the average IR file is 388 bytes. After reduction using the llvm-reduce with this proposed patch (and max-pass-iterations=10, but it always bails out earlier than that) the average reduced IR file is 250 bytes. This seems like a pretty decent win for a very simple patch, and furthermore since the default value for max-pass-iterations is 1, llvm-reduce will not be slowed down for anyone who doesn't use this new option.

I was not able to convince myself that a test for this patch would be worthwhile, instead of being fragile and silly, given the utter simplicity of the patch.

Diff Detail

Event Timeline

regehr requested review of this revision.Jan 8 2022, 2:21 PM
regehr created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 8 2022, 2:21 PM
aeubanks accepted this revision.Jan 10 2022, 10:10 AM

a good option I'll probably be using in the future

llvm/tools/llvm-reduce/DeltaManager.cpp
110

not the greatest metric, perhaps add a FIXME for a better metric?

This revision is now accepted and ready to land.Jan 10 2022, 10:10 AM
regehr added inline comments.Jan 10 2022, 2:03 PM
llvm/tools/llvm-reduce/DeltaManager.cpp
110

thanks for the review!

I'll add this fixme. I really don't have a better idea here. size of the textual IR is definitely a bit weird, but it has the advantage of encompassing all parts of the serialized IR. simpler metricss like counting instructions would fail to account for removing globals, metadata, etc.

regehr updated this revision to Diff 398805.Jan 10 2022, 6:37 PM

add FIXME suggested by @aeubanks

regehr marked an inline comment as done.Jan 10 2022, 6:38 PM
regehr closed this revision.Jan 10 2022, 9:34 PM

oof, sorry, I'm still figuring out the new interface, this is committed here:

https://reviews.llvm.org/rG4eec1710c51865b47480bc63a736a3719496679d

Just wanted to say thanks for adding this, it does look quite useful.