Translating Clang optimization flags to opt passes for bugpoint

I’m trying to debug what I think is a miscompilation that only shows up when clang is passed -O1 -vectorize-slp. I want to use bugpoint (or some other appropriate tool, if bugpoint doesn’t support the new pass manager?) to try to further whittle down the optimization passes and/or IR necessary to trigger the bug, but I’ve been having issues figuring out what passes to give to opt to reproduce the bug so I can use bugpoint.

I started with -passes='default<O1>,slp-vectorizer', since those seemed to most closely resemble the flags given to clang, but those produced an executable which did not exhibit the bug. I tried adding some other “nearby” passes as shown by the -opt-bisect-limit output, but that didn’t work, either. Some rudimentary searches didn’t seem to show a clear correspondence between the Clang -vectorize-slp flag and opt passes, but I would not be surprised if I were just looking in the wrong place.

The other flags I’ve seen when searching all appear to be for the old pass manager; in particular, something like -debug-pass=Arguments seemed like it would be helpful, but from what I could tell that is for the old pass manager. I’m tempted to try passing everything from the -opt-bisect-limit output, but that’s a rather large number of passes and I’m hoping there’s a more efficient way.

Assuming I’m looking in the right direction, how do I determine what passes to give to opt to best recreate what Clang is doing? Alternatively, is there a different approach I should be taking?

Trying to precisely translate what clang is doing into “opt” options is tricky. I usually just pass something like “-emit-llvm -mllvm -opt-bisect-limit=X” to clang, and bisect; that should give you “good” and “bad” IR, and the name of the pass that transformed the good IR to the bad IR.

At that point, if you really can’t narrow it down by looking, you can try to use bugpoint’s miscompile mode, passing in the name of the pass in question, but it’s tricky to set it up correctly.

I was using -opt-bisect-limit, but thought that perhaps bugpoint would let me get both reduced IR and a reduced set of passes. I hadn’t thought of feeding the results of bisecting using -opt-bisect-limit to bugpoint, but it’s something I’ll certainly keep in mind for next time I have to try something similar, assuming I figure out how to set up bugpoint in the first place.

-opt-bisect-limit did point me to InstCombine, but I’m not sure whether the fault is there or in a later step, as you suggested.

Thank you for the help!

I’ve added a patch at ⚙ D127221 [Clang] Enable -print-pipeline-passes in clang. that adds a -mllvm -print-pipeline-passes option to clang that allows basically the same equivalent functionality as the old -mllvm -debug-pass=Arguments.