[Patch, fortran] PR35740 - a = conjg(transpose(a)) still gives wrong results, see bug 31994

Paul Richard Thomas paul.richard.thomas@gmail.com
Sun Mar 30 13:13:00 GMT 2008


:ADDPATCH fortran:

trans-array.c contains an in-line TRANSPOSE routine that interchanges
the dimensions of the descriptor but does not copy the data.  There is
also a library function to implement transpose but this involves a
copy.

 a = transpose(conjg(a)) works correctly but  a = conjg(transpose(a))
does not.  This happens because the lines in trans-intrinsic. that
call the in-line function

      if (se->ss && se->ss->useflags)
	{
	  gfc_conv_tmp_array_ref (se);
	  gfc_advance_se_ss_chain (se);
	}
      else
	gfc_conv_array_transpose (se, expr->value.function.actual->expr);

do not work because the call to gfc_conv_tmp_array_ref (se) is never
made, since CONJG is elemental.  In addition, a temporary should be
made to avoid the dependency between the lhs and the rhs, generated by
the transpose.  Therefore, there is no loss in using the library call,
for this case.  Non-variable expressions are also getting messed up
because the offset was not calculated.  Again, this is fixed by the
library call.

The fix is to make sure that actual argument expressions of elemental
procedures never get marked as non-copying intrinsics.  This is
accomplished in resolve.c.

As a consequence, matmul (transpose (conjg (a)), b)) is going to be
more efficient that matmul (conjg (transpose (a)), b) because the
first can use the inline trick, whereas the second uses the library.
So watch your tildes and stars:)

Bootstrapped and regtested on x86_ia64/FC8 - OK for trunk and 4.3?

Paul

2008-03-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35740
	* resolve.c (resolve_function, resolve_call): If the procedure
	is elemental do not look for noncopying intrinsics.

2008-03-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/35740
	* gfortran.dg/transpose_conjg_1.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 2940 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080330/85afb089/attachment.bin>


More information about the Gcc-patches mailing list