Philipp Klaus Krause
2006-Nov-07 20:36 UTC
[LLVMdev] How do I use this to optimize C or C++ code?
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
John Criswell
2006-Nov-07 23:10 UTC
[LLVMdev] How do I use this to optimize C or C++ code?
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 > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Possibly Parallel Threads
- [LLVMdev] Optimization Levels - Need The Details
- [LLVMdev] Optimization Levels - Need The Details
- [LLVMdev] LLVM tools sufficient to build the cfrontend for windows from MinGW?
- [LLVMdev] Can I disable the optimizaiton for llvmgcc?
- [LLVMdev] Does the gcc frontend do inlining or deadcode elimination ?