1

Precondition: I invoke gcc with -O2 optimization flag and clang with -O2 optimization flag.
Does it means the options list passed to the compilers will be the same?
Do clang understand standard GCC options like -funroll-loops?

I did not find anything useful about this question in manual:
http://llvm.org/releases/3.3/tools/clang/docs/UsersManual.html
I can not even find a list of possible GCC compatible options that can be used with clang.

Do clang even do anything with GCC options (or it just ignore them?)
I just need some clarifications on how it work.

Mikhail Kalashnikov
  • 1,146
  • 1
  • 11
  • 31
  • Check clang manual for that. It understands that option but I'm not sure it'll understand ALL of them. – Adriano Repetti Dec 12 '13 at 10:52
  • There is no guarantee that `-O2` will mean the same in clang in gcc. Given that they have different optimizers, such a guarantee would not be possible anyway. – user4815162342 Dec 12 '13 at 10:55
  • 1
    @Adriano The [clang manual](http://clang.llvm.org/docs/UsersManual.html) is surprisingly silent on what optimization options it actually supports, and their meaning. – user4815162342 Dec 12 '13 at 10:55
  • @user4815162342 it's just an entry point for all documentation you need. For example [this list of optimization flags](http://llvm.org/docs/Passes.html). – Adriano Repetti Dec 12 '13 at 11:01
  • @MikhailKalashnikov just read link I posted in previous comment. Manual is an entry point for other (more exhaustive) articles. – Adriano Repetti Dec 12 '13 at 11:04
  • @Adriano The list doesn't document the meaning of `-O2`. Am I missing something? – user4815162342 Dec 12 '13 at 11:45
  • @user4815162342 no, list is documenting just optimizations made by compiler (and relative flags), it's what OP asked (_"Do clang understand standard GCC options like -funroll-loops?"_). If they're different or not...of course they are ([random pick here on SO](http://stackoverflow.com/questions/3187414/clang-vs-gcc-which-produces-better-binaries)). What each -O does? It's explained again [here on SO](http://stackoverflow.com/questions/15548023/clang-optimization-levels). – Adriano Repetti Dec 12 '13 at 12:00
  • @Adriano The OP actually asked about the meaning of clang's `-O2` compared to gcc's. The question begins with the statement that both `gcc` and `clang` are invoked with `-O2`, which leads to the question of whether the underlying optimizations are the same, and - as a consequence - does clang even understand `-funroll-loops` and such. While it is nice that an SO answer explains what `-O2` does on `clang`, it would be better to find actual documentation. In comparison, GCC documentation pretty precisely explains what flags are turned on by optimization options `-O`, `-O2`, `-O3`, `-Os`, etc. – user4815162342 Dec 12 '13 at 13:40
  • @user4815162342 I agree documentation lacks of that lists but it's pretty easy to find it (and link explains how). Anyway... – Adriano Repetti Dec 12 '13 at 13:44

1 Answers1

5

Although in general Clang attempts to copy the command-line options from GCC, there are different optimization passes in GCC and LLVM, so specific optimization flags are not shared. In particular, it means that -O2 does not behave the same in the two compilers.

If you want to see the list of optimizations that GCC applies under -O2, check its documentation; if you want to see the list Clang applies, check this related Stackoverflow question about how to see the list.

Community
  • 1
  • 1
Oak
  • 26,231
  • 8
  • 93
  • 152