Different results using -emit-llvm and llc together than just using -S?

Why would the generated assembly results for a piece of code be different if I did this:

clang -S -emit-llvm sample.c -o sample.ll
llc sample.ll -o sample.s

then if I did this:

clang -S sample.c -o sample.s

Thanks.

llc and clang have different set of defaults.

E.g. llc defaults to frame pointer elimination, etc.

Hi Ryan,

Ryan Taylor wrote:

Why would the generated assembly results for a piece of code be
different if I did this:

clang -S -emit-llvm sample.c -o sample.ll
llc sample.ll -o sample.s

then if I did this:

clang -S sample.c -o sample.s

For one example, 'llc' defaults to -O2 but clang defaults to -O0. In general, clang sets up the equivalent of an opt|llc run with a slew of flags passed in. Also, note that clang -O0 is not the same as clang -O2 -mllvm -disable-llvm-optzns, as clang chooses to emit more code which may prove useful to the optimizer, but would only waste time at -O0.

Nick

Understood; however, I see the same change/difference when calling llc -O0?

Are there any other differences between calling these separately? Or does llc not take -O levels?

Anton,

Is this true even at -O0?

Thanks.

Also, I get this issue if I run clang at -O2, so I don’t think this is an opt level issue so much.