Clang Options Warning

Hi, I want to compile my code by using the -O3 flag but the O3 should exclude some optimization passes which include block-placement and jump-threading.
I am using the following command
clang filename.c -S -O3 -mllvm -disable-block-placement -disable-jump-threading

The issue that arises is that it gives a warning which says:
clang-15: warning: argument unused during compilation: '-disable-jump-threading' [-Wunused-command-line-argument]

Now, I want to ask that is it the right way to exclude some passes from O3? And if it is the right way, how can I disable jump-threading?

The specific warning is because -mllvm only applies to the next argument so you need -mllvm -disable-block-placement -mllvm -disable-jump-threading.

As for the right way, I don’t think that’s really something LLVM encourages in the first place (certainly a lot less than GCC which had loads of optimization pipeline tweaks available to workaround bugs and other issues last time I dealt with it). We try to encourage fixing the pass itself so that it can handle the edge-case.

But if you’re using Clang and need to do it anyway, I can’t think of an alternative route (other front-ends would of course customize how they built the pipeline).

1 Like

I tried using the -mllvm twice but the clang gives an error and does not accept the second -mllvm

Ah yes, I didn’t check the argument actually exists. As I said, LLVM doesn’t encourage tinkering with the pipeline and part of that is not every pass has an option to disable it (probably most don’t).

In this case you might be able to use -jump-threading-threshold=0 instead, but I wouldn’t swear to it.

Ah. I’ll give it a try. Is there some way I can disable these passes using some C or Cpp or TableGen File?

What I mean to say is that where in the LLVM is it defined to use these passes in -O3?

There are currently two possible pass managers in LLVM (we’re trying to get rid of one). In the new scheme I believe it’s llvm/lib/Passes/PassBuilderPipelines.cpp, in the old one llvm/lib/Transforms/IPO/PassManagerBuilder.cpp (search for JumpThreading for example).

OK Thanks!