llvm-ld doesn't honor -Ox

The project that I use to test LLVM against showed that currently
llvm-ld doesn't honor the -Ox switch.

$ /usr/src/llvm/dist/bin/llvm-ld \
  -v -stats -native -O1 -strip-all \
  -o main \
  -L/usr/share/qt3/lib -L/usr/X11R6/lib \
  -lcrypto -lusb -lutil -lqt-mt -lXext -lX11 -lm -lpthread
...
$ size main
   text data bss dec hex filename
1128271 71980 8392 1208643 127143 main
$ /usr/src/llvm/dist/bin/llvm-ld \
  -v -stats -native -O5 -strip-all \
  -o main \
  -L/usr/share/qt3/lib -L/usr/X11R6/lib \
  -lcrypto -lusb -lutil -lqt-mt -lXext -lX11 -lm -lpthread
$ size main
   text data bss dec hex filename
1128271 71980 8392 1208643 127143 main

As you see, I put "-stats" into the command lines, so I get some
statistics. In both cases I get the same stats (below). Should'nt
-O5 run more passes than -O1 ?!?

   3 argpromotion - Number of aggregate arguments promoted
  25 constmerge - Number of global constants merged
   2 deadargelim - Number of unread args removed
   0 deadargelim - Number of unused return values removed
  29 dse - Number of stores deleted
1103 gcse - Number of instructions removed
  17 gcse - Number of instructions removed due to non-instruction values
316 gcse - Number of loads removed
   1 globaldce - Number of global variables removed
   3 globalopt - Number of functions converted to fastcc
   8 globalsmodref-aa - Number of functions that do not access memory
  57 globalsmodref-aa - Number of functions that only read memory
128 globalsmodref-aa - Number of functions without address taken
  14 globalsmodref-aa - Number of global vars without address taken
   9 inline - Number of functions deleted because all callers found
496 inline - Number of functions inlined
  12 instcombine - Number of constant folds
512 instcombine - Number of dead inst eliminated
   3 instcombine - Number of dead stores eliminated
  70 instcombine - Number of instructions sunk
876 instcombine - Number of insts combined
   2 licm - Number of call insts hoisted or sunk
539 licm - Number of instructions hoisted out of loop
  37 licm - Number of instructions sunk out of loop
   7 licm - Number of load insts hoisted or sunk
   5 loopsimplify - Number of nested loops split out
893 loopsimplify - Number of pre-header or exit blocks inserted
   2 scalarrepl - Number of allocas broken up
   6 scalarrepl - Number of allocas promoted
   4 sccp - Number of basic blocks unreachable by IPSCCP
  23 sccp - Number ofinstructions removed by IPSCCP
1159 simplifycfg - Number of blocks simplified

Holger Schurig wrote:

The project that I use to test LLVM against showed that currently
llvm-ld doesn't honor the -Ox switch.

You're entirely right. It appears that llvm-ld is still programmed to
use the -disable-opt and -disable-inline options. That should be fixed.

The code is in tools/llvm-ld/Optimize.cpp for anyone interested.

Nick