This is the mail archive of the
mailing list for the GCC project.
Re: [fortran PATCH] Implement a(:,:) = 0.0 using memset (take 2)
On Mon, Dec 18, 2006 at 06:55:22PM -0700, email@example.com wrote:
> 2006-12-18 Roger Sayle <firstname.lastname@example.org>
> * trans-expr.c (is_zero_initializer_p): Determine whether a given
> constant expression is a zero initializer.
> (gfc_trans_zero_assign): New function to attempt top optimize
> "a(:) = 0.0" as a call to __builtin_memset (a, 0, sizeof(a));
> (gfc_trans_assignment): Special case array assignments to zero
> initializer constants, using gfc_trans_zero_assign.
> * gfortran.dg/array_memset_1.f90: New test case.
I think this is OK for trunk; however, Andrew did bring up
the potential problem of a signed zero. I'm not sure if
-0 occurs very often in Fortran code, but we can guard against
this by changing your code
> + case BT_REAL:
> + return mpfr_sgn (expr->value.real) == 0;
return (mpfr_sgn (expr->value.real) == 0
&& MPFR_SIGN (expr->value.real) == 1);
> + case BT_COMPLEX:
> + return mpfr_sgn (expr->value.complex.r) == 0
> + && mpfr_sgn (expr->value.complex.i) == 0;
A similar change is needed above.
MPFR_SIGN retrieves the sign bit from the mpfr_t structure.
As a side note, I found that your patch provides a 7.2% decrease
in computation time for the Bergen Ocean Model (ie., your patch
is beneficial!). There are 176 __builtin_memset calls in BOM
due to your patch.