[flang-commits] [flang] [flang][Driver] Enable -Os and -Oz in flang (PR #164707)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Oct 23 05:21:39 PDT 2025


tblah wrote:

> > Does Os and Oz run with optimization level 2?
> 
> Yes. This intentionally mirrors clang's implementation. Some LLVM optimizations like [IPSCCP](https://github.com/llvm/llvm-project/blob/4f4bee428d2269808f2ef5f97f3482382d18945d/llvm/lib/Passes/PassBuilderPipelines.cpp#L1962), [inlining](https://github.com/llvm/llvm-project/blob/4f4bee428d2269808f2ef5f97f3482382d18945d/llvm/lib/Passes/PassBuilderPipelines.cpp#L808) (or [here](https://github.com/llvm/llvm-project/blob/4f4bee428d2269808f2ef5f97f3482382d18945d/llvm/lib/Passes/PassBuilderPipelines.cpp#L914)) examine this level internally, but I haven't looked at exactly how these are affected.
> 
> We could do something different in `flang` to be more aggressive, but that would be a more involved change since we may need to build flang-specific pass pipelines. We could also disable some FIR-level optimizations, but I haven't looked into that.
> 
> Do you think that should be done as part of this PR?

I think what Kiran is referring to is the MLIR pass pipeline inside of flang. I don't think there is any equivalent to this in clang. See `flang/lib/Optimizer/Pipelines.cpp`. Some optional optimisations are only enabled when `pc.OptLevel.isOptimizingForSpeed()`. I suspect a subset of these (plus LoopVersioning and maybe others)) should not be enabled when optimising for size. There are lit tests for the pipeline which should be updated to reflect what the pipeline is when optimising for size.

https://github.com/llvm/llvm-project/pull/164707


More information about the flang-commits mailing list