How do I use this to optimize C or C++ code?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I use this to optimize C or C++ code?

Philipp Klaus Krause
I tried
llvm-gcc -c test.c
llvm-gcc test.o
llc -march=c test.bc -f -o test2.c

Then I compiled both test.c and test2.c with sdcc, a compiler which
lacks high-level optimization. The code generated from test2.c was
bigger. Then I tried

llvm-gcc -O5 -Os -c test.c
llvm-gcc -O5 -Os test.o
llc -march=c test.bc -f -o test2.c

But it generated exactly the same code as the commands above.
What is it that I'm doing wrong? I expected llvm to optimize my code for
size, instead it gets worse.

Philipp
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: How do I use this to optimize C or C++ code?

John Criswell
Philipp Klaus Krause wrote:

> I tried
> llvm-gcc -c test.c
> llvm-gcc test.o
> llc -march=c test.bc -f -o test2.c
>
> Then I compiled both test.c and test2.c with sdcc, a compiler which
> lacks high-level optimization. The code generated from test2.c was
> bigger. Then I tried
>
> llvm-gcc -O5 -Os -c test.c
> llvm-gcc -O5 -Os test.o
> llc -march=c test.bc -f -o test2.c
>  
If you are using llvm-gcc3 (i.e. the old LLVM GCC front end based on a
pre-release of GCC 3.4), then llvm-gcc does not control the
optimizations that the LLVM tools use to optimize your code.  In both
cases, you've run the default optimizations that gccas and gccld run.

To turn optimization off, use -Wa,-disable-opt -Wl,-disable-opt on the
llvm-gcc command line.  These will tell gccas and gccld to turn off
*all* of their optimizations.

The new LLVM GCC front end from Apple (known as llvm-gcc4) might control
optimization from the llvm-gcc command line; someone more familiar with
it will have to chime in.
> But it generated exactly the same code as the commands above.
> What is it that I'm doing wrong? I expected llvm to optimize my code for
> size, instead it gets worse.
>  
I'm no expert in LLVM optimizations; however, I am under the impression
that all of the default LLVM optimizations were designed to optimize for
execution time and not space.  Someone with more knowledge on the matter
will need to verify that, though.

Regards,

-- John T.

> Philipp
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>  

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev