[PATCH] PR fortran/31593: Speed up loops with DO variables as procedure arguments

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Tue Aug 25 20:32:00 GMT 2009


Hi Dominique,

Dominique Dhumieres wrote:
> To summarize that, I get:
> 
> [ibook-dhum] lin/test% gfc -m64 -O2 -funsafe-math-optimizations air.f90
> [ibook-dhum] lin/test% time a.out > /dev/null
> 8.459u 0.046s 0:08.51 99.7%	0+0k 0+7io 0pf+0w
> [ibook-dhum] lin/test% gfc -fwhole-file -m64 -O2 -funsafe-math-optimizations air.f90
> [ibook-dhum] lin/test% time a.out > /dev/null
> 8.468u 0.046s 0:08.52 99.7%	0+0k 0+7io 0pf+0w
> [ibook-dhum] lin/test% /Volumes/MacBook/opt/gcc/gcc4.5w-do/bin/gfortran -m64 -O2 -funsafe-math-optimizations air.f90
> [ibook-dhum] lin/test% time a.out > /dev/null
> 10.168u 0.046s 0:10.22 99.8%	0+0k 0+9io 0pf+0w
> [ibook-dhum] lin/test% /Volumes/MacBook/opt/gcc/gcc4.5w-0/bin/gfortran -m64 -O2 -funsafe-math-optimizations air.f90
> [ibook-dhum] lin/test% time a.out > /dev/null
> 8.407u 0.045s 0:08.46 99.7%	0+0k 0+8io 0pf+0w
> 
> where gcc4.5w-do is with your patch and gcc4.5w-0 is with
> a '0 && ' insterted in the line 966 of trans-stmt.c, i.e. in
> the block:
> 
>   /* Special case simple loops.  */
>   if (TREE_CODE (type) == INTEGER_TYPE
>       && (integer_onep (step)
>         || tree_int_cst_equal (step, integer_minus_one_node)))
>     return gfc_trans_simple_do (code, &block, dovar, from, to, step);
> 
> I also checked that the fast codes have a small count of pow().

thanks for doing this.  Is the difference between 8.407 and 8.459 
significant?

My patch affects exactly one loop in air.f90, which I quote here:
       DO i = 1 , NDX
          READ (9,*) spx(i) , epx(i) , NPX(i)
          WRITE (6,*) i , spx(i) , epx(i) , NPX(i)
       ENDDO

As you can deduce, the bad impact of my patch is due to the modified 
program exposing some bad behavior in one of the optimizers, not because 
my patch is doing something silly.  It's no wonder I kept seeing 
paradoxical results with all the other things I've tried.

Cheers,
- Tobi



More information about the Fortran mailing list