Difference between clang -Oz and opt -Oz

Dear LLVMers,

Why does opt -Oz and clang -Oz produce different codes? And could
someone point me to some documentation/discussion that explains the
differences between them?

Regards,

Fernando

clang -fno-legacy-pass-manager -S -emit-llvm -Oz
populates the pipeline with PassBuilder::buildPerModuleDefaultPipeline

If you use
clang -fno-legacy-pass-manager -S -emit-llvm -Oz -Xclang -disable-llvm-passes
opt -S -passes='default<Oz>'
the behavior will be quite similar, though the variable naming will be
different.

Dear Fang-rui,

    Thank you very much for the detailed answers. That was very nice!

Happy New Year,

Fernando