opt, llcc, ll++, -O1, -O2, -O3

Hi devels,

there are two issues concerning invoking
optimizations:

1.

this document:

  http://llvm.cs.uiuc.edu/docs/GettingStarted.html

is very nice, it would be good though to add in a section

  An Example Using the LLVM Tool Chain

examples on optimization step.

2.
If i am not wrong there is no tool, which integrates all
steps:

llvmgcc->opt->llc into something like llcc
(and llvmg++->opt->llc into something like ll++),
where options -O1, -O2, -O3 are available. For example,
`llcc -O3 ackerman.c' should make similar (but better!)
things as `gcc -O3 ackerman.c' does.

Anyway, it would be good to have a starting point
for those who'd like to try "fully LLVM-optimized"
C/C++ code. Indeed, the tool "opt" has quite big
set of options...

best regards,

there are two issues concerning invoking optimizations:

1.
this document:
  http://llvm.cs.uiuc.edu/docs/GettingStarted.html
is very nice, it would be good though to add in a section

  An Example Using the LLVM Tool Chain

examples on optimization step.

That's an interesting idea. LLVM currently enables the maximal
optimizations by default, you can only disable options. For example, you
can use -Wl,-disable-inlining to disable the link-time inliner, or
-Wl,-disable-opt to disable all link-time optimizations. Unfortunately we
don't have a centralized place that lists all of the optimizations that
can be disabled (this should be added to the command guide), but you can
see them by using 'gccas --help' or 'gccld --help'. To disable a gccas
option, use -Wa,-disable-foo, for gccld, use -Wl,-disable-foo on the
llvmgcc command line.

Additionally, you can use opt to run individual optimizations, of which
there are a lot. :slight_smile:

I added the following patch to the GSG. If you have a better suggestion,
please let me know:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040426/014073.html

2.
If i am not wrong there is no tool, which integrates all
steps:

llvmgcc->opt->llc into something like llcc
(and llvmg++->opt->llc into something like ll++),
where options -O1, -O2, -O3 are available. For example,
`llcc -O3 ackerman.c' should make similar (but better!)
things as `gcc -O3 ackerman.c' does.

You should be able to do this with the gccld -native or -native-cbe
options:

For example:
$ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe

... compiles to a native 'ackerman' executable, using the C backend. These
are link-time options, so you can compile any way you normally would, for
example by using 'llvmgcc -c x.c -o x.o', as long as the flag gets passed
in when the program is linked.

If you use the -native option, it uses LLC, though it doesn't turn on
Alkis's nice register allocator. If you want to enable the linearscan
allocator with the -native option, you currently have to hack
llvm/tools/gccld/GenerateCode.cpp:GenerateAssembly to pass in the
'-regalloc=linearscan' option. When this allocator is completely stable,
we will enable it by default.

Anyway, it would be good to have a starting point for those who'd like
to try "fully LLVM-optimized" C/C++ code. Indeed, the tool "opt" has
quite big set of options...

Yup, it looks like opt has 75 optimizer passes available in it right now.
:slight_smile: If you start playing with them, make sure to avoid the "experimental
optimizations", which are not likely to work well:
http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html#experimental

LLVM really needs an optimizer guide that lists the various
optimizations, the high-level overview of what they do, the algorithms
used, useful-to-know-about interactions between passes (e.g. a pass that
leaves around a lot of unpropagates constants), and when they are likely
to be useful (most of this information is available in the comments at
the top of the file for the optimization). This has been on my TODO list
for about 2.5 years now, but I have a *very* long TODO list. :slight_smile:

Here are some examples of the header comments:
http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=1.5&content-type=text/x-cvsweb-markup
http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=1.16&content-type=text/x-cvsweb-markup
http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/LICM.cpp?rev=1.59&content-type=text/x-cvsweb-markup
http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/Reassociate.cpp?rev=1.30&content-type=text/x-cvsweb-markup
http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=1.13&content-type=text/x-cvsweb-markup

-Chris

Chris Lattner wrote:

there are two issues concerning invoking optimizations:

1.
this document:
http://llvm.cs.uiuc.edu/docs/GettingStarted.html
is very nice, it would be good though to add in a section

An Example Using the LLVM Tool Chain

examples on optimization step.

That's an interesting idea. LLVM currently enables the maximal
optimizations by default, you can only disable options. For example, you
can use -Wl,-disable-inlining to disable the link-time inliner, or
-Wl,-disable-opt to disable all link-time optimizations. Unfortunately we
don't have a centralized place that lists all of the optimizations that
can be disabled (this should be added to the command guide), but you can
see them by using 'gccas --help' or 'gccld --help'. To disable a gccas
option, use -Wa,-disable-foo, for gccld, use -Wl,-disable-foo on the
llvmgcc command line.

Additionally, you can use opt to run individual optimizations, of which
there are a lot. :slight_smile:

I added the following patch to the GSG. If you have a better suggestion,
please let me know:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040426/014073.html

2.
If i am not wrong there is no tool, which integrates all
steps:

llvmgcc->opt->llc into something like llcc
(and llvmg++->opt->llc into something like ll++),
where options -O1, -O2, -O3 are available. For example,
`llcc -O3 ackerman.c' should make similar (but better!)
things as `gcc -O3 ackerman.c' does.

You should be able to do this with the gccld -native or -native-cbe
options:

Just to clarify, because I think it can be easily overlooked:

The gccas and gccld programs are not just assemblers/linkers; they are also optimizers too. gccas runs optimizations after assembling the file, and gccld runs interprocedural optimizations at link time. This is why you don't need to use the opt program when using llvm-gcc and llvm-g++; gccld and gccas run the optimizations for you.

Contrast this to llvm-as and llvm-link: they do not do any optimization (that I am aware of). They only assemble and link LLVM code.

-- John T.

hi all,

well, i have set up proper command line parameters for
for C-Shootout tests to get reasonable running time
for benchmarking. I have compared "gcc -O3" and
"llvmgcc -Wl,-native-cbe"

here goes output (which shows that llvm is already
better for test with intensive function calls):

time -p ./gcc_ackermann 11
user 2.36
time -p ./llvm_ackermann 11
user 1.07

For example:
$ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe

BTW, Chris, what should be then an analogy
of "gcc -O3 -S foo.c" in LLVM framework?

The invocation of

$ llvmgcc -S ackerman.c -o ackerman -Wl,-native-cbe

does not produce native assebler output as one might expect.

Valery A.Khamenya wrote:

For example: $ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe

BTW, Chris, what should be then an analogy of "gcc -O3 -S foo.c" in LLVM framework?
The invocation of
  $ llvmgcc -S ackerman.c -o ackerman -Wl,-native-cbe
does not produce native assebler output as one might expect.

If you're wanting native assembler code, one way to do it would be:

llvmgcc -o ackerman ackerman.c # Produces ackerman.bc, a linked LLVM
                                # bytecode file
llc -o ackerman.s ackerman.bc # Generates native assembly from linked
                                # LLVM bytecode

Note that this will statically link all of the library functions in libc that are currently available as LLVM bytecode, so this file may be a little large.

If you want the native code for only the code in ackerman.c, just replace the first line with:

llvmgcc -c -o ackerman.bc ackerman.c # Compiles but doesn't link

-- John T.

Alternatively, if you'd like to get native code with the C backend, you
should replace the llc line with:

llc -o ackerman.cbe.c ackerman.bc -march=c
gcc -O3 ackerman.cbe.c -o ackerman.s -S

Oh, and if you're playing with the LLVM native code generators, consider
adding the -regalloc=linearscan option. Not doing so will make the code
really horrible. :slight_smile:

-Chris

hi all,

well, i have set up proper command line parameters for
for C-Shootout tests to get reasonable running time
for benchmarking. I have compared "gcc -O3" and
"llvmgcc -Wl,-native-cbe"

Cool. Each of these benchmarks has a default problem size for when no
arguments are specified (take a look in the main for each benchmark). If
you could modify the benchmark programs to default to the sizes you
specified, and send me the diff, I would be happy to apply it. :slight_smile:

-Chris

here goes output (which shows that llvm is already
better for test with intensive function calls):

time -p ./gcc_ackermann 11
user 2.36
time -p ./llvm_ackermann 11
user 1.07

----
time -p ./gcc_ary3 300000
user 2.86
time -p ./llvm_ary3 300000
user 3.19

----
time -p ./gcc_fib2 39
user 2.32
time -p ./llvm_fib2 39
user 1.61

----
time -p ./gcc_hash 1000000
user 2.26
time -p ./llvm_hash 1000000
user 2.30

----
time -p ./gcc_heapsort 2000000
user 2.57
time -p ./llvm_heapsort 2000000
user 3.26

----
time -p ./gcc_lists 500000
user 2.70
time -p ./llvm_lists 500000
user 3.27

----
time -p ./gcc_matrix 500000
user 2.61
time -p ./llvm_matrix 500000
user 4.17

----
time -p ./gcc_methcall 90000000
user 2.83
time -p ./llvm_methcall 90000000
user 2.89

----
time -p ./gcc_nestedloop 33
user 2.40
time -p ./llvm_nestedloop 33
user 3.66

----
time -p ./gcc_objinst 10000000
user 2.25
time -p ./llvm_objinst 10000000
user 2.12

----
time -p ./gcc_random 60000000
user 2.42
time -p ./llvm_random 60000000
user 2.42

----
time -p ./gcc_sieve 25000
user 2.41
time -p ./llvm_sieve 25000
user 4.36

----
time -p ./gcc_strcat 50000000
user 2.77
time -p ./llvm_strcat 50000000
user 3.98

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

-Chris

> well, i have set up proper command line parameters for
> for C-Shootout tests to get reasonable running time
> for benchmarking. [...]

Each of these benchmarks has a default problem size for when no
arguments are specified (take a look in the main for each benchmark). If
you could modify the benchmark programs to default to the sizes you
specified, and send me the diff, I would be happy to apply it. :slight_smile:

If you do so, I would like to suggest that there be some kind of flag
for running Shootout with the tiny, default problem sizes, which are
appropriate for the kind of "smoke tests" that I like to run.

Thanks!

Cool. Each of these benchmarks has a default problem size for when

no

arguments are specified (take a look in the main for each

benchmark). If

you could modify the benchmark programs to default to the sizes you
specified, and send me the diff, I would be happy to apply it. :slight_smile:

done.

check your email, please.