This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++ optimisation fails badly


Andrew Dorrell wrote:

> for i in 1 2 3; do time ./bug $i; done
>
> real    0m0.102s
> user    0m0.023s
> sys     0m0.075s
>
> real    0m0.788s
> user    0m0.564s
> sys     0m0.212s
>
> real    0m0.296s
> user    0m0.074s
> sys     0m0.213s
>
>
> Notice in this case test 2 (user 0.564s) takes 7 times as long as
> test 3 (user    0m0.074s) which performs exactly the same amount of
> work!

This is fixed on mainline CVS. It's one of the hundreds of cases where the new
tree-ssa optimizers are doing their job really well:

for i in 1 2 3; do time ./a.out $i; done

real    0m1.048s
user    0m0.110s
sys     0m0.900s

real    0m3.226s
user    0m0.150s
sys     0m2.960s

real    0m3.301s
user    0m0.140s
sys     0m3.080s

If you compare the real time, the second and third tests take exactly three
times the first test, which is what you would expect given they do three times
more operations. In fact, looking into the optimized dump of the compiler, this
is how the three main loops look like:


*******  test 1  *******
<L3>:;
  T.13 = *arg2;
  *arg2 = (T.13 + T.13) / 2;
  arg2 = arg2 + 4B;
  if (end > arg2) goto <L3>; else goto <L6>;


*******  test 2  *******
<L11>:;
  T.25 = r->c;
  T.27 = r->b;
  T.29 = r->a;
  r->a = (T.29 + T.29) / 2;
  r->b = (T.27 + T.27) / 2;
  r->c = (T.25 + T.25) / 2;
  r = r + 12B;
  if (end > r) goto <L11>; else goto <L16>;


*******  test 3  *******
<L21>:;
  T.16 = arg2->c;
  T.19 = arg2->b;
  T.22 = arg2->a;
  arg2->a = (T.22 + T.22) / 2;
  arg2->b = (T.19 + T.19) / 2;
  arg2->c = (T.16 + T.16) / 2;
  arg2 = arg2 + 12B;
  if (end > arg2) goto <L21>; else goto <L24>;


As you can see, the whole abstraction layer has been completely removed.

Giovanni Bajo



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]