Running verify between every opt pass?

Hi,

Is there any easy way to run the verifier between each pass in opt if I do e.g. opt -O3 foo.ll -o foo.opt.ll ?

If I add -verify after -O3 I get one invocation of the verifier first in the FunctionPass manager and then get two (!) runs of the verifier after all other passes are run.

Then I saw the flag -verify-each which sounds promising, the help text says

  - Verify after each transform

but if I do

-O3 -verify-each

it still looks like the verifier is only run once, first in the FunctionPass manager?

Is there any way to do this somewhat easily?

(And the reason I got interested in this is that we've recently seen a bug in the loop-vectorizer where a verifer invocation would have complained, but without it the resulting code from opt was wrong which later caused the code to do the wrong thing at runtime.

And running a single verifier pass after all of the opt passes wouldn't have caught it either because some other pass had already rewritten the code by then so the verifier wouldn't complain anymore.)

Thanks,
Mikael

Hi,

Is there any easy way to run the verifier between each pass in opt if I do e.g. opt -O3 foo.ll -o foo.opt.ll ?

I don’t think so.

If I add -verify after -O3 I get one invocation of the verifier first in the FunctionPass manager and then get two (!) runs of the verifier after all other passes are run.

Then I saw the flag -verify-each which sounds promising, the help text says

- Verify after each transform

but if I do

-O3 -verify-each

it still looks like the verifier is only run once, first in the FunctionPass manager?

The verify-each flag only works for passes that are specified on the command line, it does not operate on O3.

Is there any way to do this somewhat easily?

As a workaround, you can get the list of passes that matches O3:

echo "" | opt -O3 -debug-pass=Arguments

And the re-run opt with all theses passes on the command line instead of O3.

Mehdi, as you said yes this is a workaround but this is not portable and i think the scenario mentioned here could occur in general. So running verify pass after each pass is useful… May be we should invoke verify pass after each pass in O3 under an option say --verify-after-each? In other words, opt will invoke verify pass after each pass only if the above option is provided.

Mehdi, as you said yes this is a workaround but this is not portable

Not sure what you mean by “not portable”?

and i think the scenario mentioned here could occur in general. So running verify pass after each pass is useful… May be we should invoke verify pass after each pass in O3 under an option say --verify-after-each? In other words, opt will invoke verify pass after each pass only if the above option is provided.

Patch welcome :slight_smile:
Not sure what’s the best way to implement it though…

Mehdi, as you said yes this is a workaround but this is not portable

Not sure what you mean by “not portable”?

and i think the scenario mentioned here could occur in general. So running verify pass after each pass is useful… May be we should invoke verify pass after each pass in O3 under an option say --verify-after-each? In other words, opt will invoke verify pass after each pass only if the above option is provided.

Patch welcome :slight_smile:
Not sure what’s the best way to implement it though…

Would it be possible to make it an “analysis” pass, which every other pass requires when the flag “verify-after-each” is on, and which is always invalid (i.e. before every pass we “recompute" it)?

Michael