Skip to content

Instantly share code, notes, and snippets.

@lolo32
Last active December 5, 2024 15:34
Show Gist options
  • Save lolo32/fd8ce29b218ac2d93a9e to your computer and use it in GitHub Desktop.
Save lolo32/fd8ce29b218ac2d93a9e to your computer and use it in GitHub Desktop.

CLang optimizations on Mac OSX

Version:

Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

This was made with commands:

echo 'int;' | clang -xc -O0    - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -O1    - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -O2    - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -O3    - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -Ofast - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -Os    - -o /dev/null -\#\#\#
echo 'int;' | clang -xc -Oz    - -o /dev/null -\#\#\#
  • -O0 means "no optimization": this level compiles the fastest and generates the most debuggable code. It enable -mrelax-all option.
  • -O1 somewhere between -O0 and -O2.
  • -O2 moderate level of optimization which enables most optimizations.
  • -O3 is like -O2 except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster).
  • -Ofast enable -O3, with other aggressive optimizations that may violate strict compliance with language standards. It speedup math calculations.
  • -Os is like -O2 with extra optimizations to reduce code size.
  • -Oz is like -Os, but try to minimise even more the code size.
Option -O0 -O1 -O2 -O3 -Ofast -Os -Oz Description
-triple x86_64-apple-macosx10.10.0 Specify target triple
-emit-obj Emit native object files
-mrelax-all (integrated-as) Relax all machine instructions
-disable-free Disable freeing of memory on exit
-disable-llvm-verifier Don't run the LLVM IR verifier pass
-mrelocation-model pic The relocation model to use
-pic-level 2 Value for __PIC__
-mdisable-fp-elim Disable frame pointer elimination optimization
-menable-no-infs Allow optimization to assume there are no infinities.
-menable-no-nans Allow optimization to assume there are no NaNs.
-menable-unsafe-fp-math Allow unsafe floating-point math optimizations which may decrease precision
-ffp-contract=fast Form fused FP ops (e.g. FMAs): fast (everywhere) OR on (according to FP_CONTRACT pragma, default) OR off (never fuse)
-ffast-math Enable the frontend's 'fast-math' mode. This has no effect on optimizations, but provides a preprocessor macro __FAST_MATH__ the same as GCC's -ffast-math flag
-masm-verbose Generate verbose assembly output
-munwind-tables Generate unwinding tables for all functions
-target-cpu core2 Target a specific cpu type
-target-linker-version 241.9 Target linker version
-resource-dir The directory which holds the compiler resource files
-fdebug-compilation-dir The compilation directory to embed in the debug info.
-ferror-limit 19 Set the maximum number of errors to emit before stopping (0 = no limit).
-fmessage-length 117 Format message diagnostics so that they fit within N columns or fewer, when possible.
-stack-protector 1 Enable stack protectors
-mstackrealign Force realign the stack at entry to every function
-fblocks Enable the 'blocks' language feature
-fobjc-runtime Specify the target Objective-C runtime kind and version
-fencode-extended-block-signature enable extended encoding of block type signature
-fdiagnostics-show-option Print option name with mappable diagnostics
-fcolor-diagnostics Use colors in diagnostics
-vectorize-loops Run the Loop vectorization passes
-vectorize-slp Run the SLP vectorization passes
@GavinRay97
Copy link

Thanks for this, super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment