Issue 63788
Summary Unable to replicate clang optimization pipeline using opt with LLVM 16
Labels new issue
Assignees
Reporter lucasreis1
    I've been experimenting with optimization via Clang and I'm in need of a custom optimization pipeline for IR. I figured that I would start by replicating `clang -O3` using opt and remove passes I don't need. 

A few quick tests showed me that for a specific application, Clang produced a binary that is 10% faster than when using opt. I've tried mimicking everything Clang does up until codegen except for optimizations, which I apply at opt. The result is still visible.

Here's a summary of my pipeline:

```
clang -c -emit-llvm -O3 a.cpp
clang -c -emit-llvm -O3 b.cpp
clang -c -emit-llvm -O3 c.cpp
llvm-link a.bc b.bc c.bc -o from_clang.bc
```

```
clang -Xclang -mframe-pointer=all -Xclang -vectorize-loops -Xclang vectorize-slp  -Xclang -disableO0-optnone -c -emit-llvm a.bc
opt a.bc -passes="default<O3>" -o a.bc
clang -Xclang -mframe-pointer=all -Xclang -vectorize-loops -Xclang vectorize-slp  -Xclang -disableO0-optnone -c -emit-llvm b.cpp
opt b.bc -passes="default<O3>" -o b.bc
clang -Xclang -mframe-pointer=all -Xclang -vectorize-loops -Xclang vectorize-slp  -Xclang -disableO0-optnone -c -emit-llvm c.cpp
opt c.bc -passes="default<O3>" -o c.bc

llvm-link a.bc b.bc c.bc from_opt.bc
```

When generating binaries, `from_clang.bc` was 10% faster than `from_opt.bc`.

To my understanding, [Clang's optimization pipeline](https://github.com/llvm/llvm-project/blob/release/16.x/clang/lib/CodeGen/BackendUtil.cpp#L992C1-L992C1) is [identical to opt's](https://github.com/llvm/llvm-project/blob/release/16.x/llvm/lib/Passes/PassBuilder.cpp#L1207) when running the new pass manager.

So, is there anything I'm missing here? How come the results are so different between these two binaries with alleged identical optimization pipelines?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to