This patch teaches llvm-reduce to run opt passes. The rationale for this comes in three parts:
- opt passes have the potential to usefully shrink test cases in ways that are more powerful than the existing delta passes that we have. for example, SROA cleans up a lot of allocas, InstCombine does lots of other simplifications, etc.
- running opt passes can bring the test case closer to the actual input that gets miscompiled. consider an example where we're reducing some unoptimized IR that gets miscompiled 25 passes into the phase ordering. by running some of these earlier passes, we make the test case into something that is more directly miscompiled, making it easier to understand what's going on and also making it easier to tell if the bug trigger is a duplicate.
- opt passes try to canonicalize the code, and we like canonicalization because for those of us who read a lot of canonical IR it's easier to understand. if there are non-canonical aspects to our test case that are inessential for triggering a bug, we should eliminate them.
A drawback of this patch is that it makes llvm-reduce run slower -- on my machine, this patch makes my machine take 2.4 seconds instead of 1.6 seconds to run all of the llvm-reduce test cases. The other drawback that I can think of is that if we're trying to reduce a file that crashes one of the passes we're trying to run, llvm-reduce will also crash (I have a solution to this, but was hoping to land this patch first).
One thing to discuss is the set of passes that we run here, I've just gone and picked some by hand that seem like they are mostly going to simplify the code, but am open to discussion about which passes make the most sense.
Another thing we could discuss is when to run the opt passes. Here I have them running right at the beginning, when there should be lots of opportunities for them to clean things up, but we could also make an argument for running them at the end of the llvm-reduce phase ordering so that they'll canonicalize the IR as much as possible before it gets dumped out for human consumption.
I'd actually prefer not to have internal as the canonical reduced output, it's more likely to get thrown away by accident and also increases the amount of text in the output. ditto with tail calls