Bug 35740 - a = conjg(transpose(a)) still gives wrong results, see bug 31994
Summary: a = conjg(transpose(a)) still gives wrong results, see bug 31994
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.3
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-28 19:16 UTC by Dominik Muth
Modified: 2008-03-30 14:25 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-03-29 06:38:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominik Muth 2008-03-28 19:16:54 UTC
conjg(transpose(a)) still gives wrong results, if it is assigned to a. transpose(conjg(a)) works.

program main
  implicit none
  complex, dimension(2,2) :: a,b,c
  a(1,1) = (1.,1.)
  a(2,1) = (2.,2.)
  a(1,2) = (3.,3.)
  a(2,2) = (4.,4.)
  print *, "original:                     ",a
  b = conjg(transpose(a))
  print *, "H(a) - once wrong, now right: ",b
  c = transpose(a)
  c = conjg(c)
  print *, "H(a) - right:                 ",c
  a = conjg(transpose(a))
  print *, "H(a) - still wrong:           ",a
  a = transpose(c)
  a = conjg(a)
  a = transpose(conjg(a))
  print *, "H(a) - hack around:           ",a
END program main

gfortran -v:

Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --disable-libmudflap --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.3 (Debian 4.2.3-1)
Comment 1 Tobias Burnus 2008-03-28 19:58:54 UTC
Confirm. There seems to be a temporary missing.

Paul, you have fixed PR 31994, do you have an idea here?

The problem seems to be in general expressions of this type:

  array = function(transpose(array))

where function() can be, e.g., "sin()" and the data type, e.g., real since then no temporary is created. If possible, we should backport a fix to 4.2 and 4.3.
Comment 2 Paul Thomas 2008-03-29 06:38:40 UTC
(In reply to comment #1)
> Confirm. There seems to be a temporary missing.
> 
> Paul, you have fixed PR 31994, do you have an idea here?

Tobias,

I'll put my thinking cap on.  Our conjg(tranpose()) trick is efficoent, of course, but it keeps on tripping us up.

Cheers

Paul
Comment 3 Paul Thomas 2008-03-29 07:27:44 UTC
(In reply to comment #2)
Hah!  It's still worse than I thought.  Not only is a temporary not made but the scalarizer is being blown out of the water by the likes of:

program main
  implicit none
  complex, dimension(2,2) :: a,b,c,d
  a(1,1) = (1.,1.)
  a(2,1) = (2.,2.)
  a(1,2) = (3.,3.)
  a(2,2) = (4.,4.)
  b = a
  c = (0.0,0.0)
  b = conjg(transpose(b + c))
  print *, "H(a) -        wrong:           ",b
  b = a
  b = transpose(conjg(b + c))
  print *, "H(a) -           OK:           ",b
  b = a
  d = conjg(transpose(b + c))
  b = d
  print *, "H(a) - really wrong:           ",b
 END program main

Paul
Comment 4 Paul Thomas 2008-03-30 14:14:06 UTC
Subject: Bug 35740

Author: pault
Date: Sun Mar 30 14:13:21 2008
New Revision: 133729

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133729
Log:
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.

Added:
    trunk/gcc/testsuite/gfortran.dg/transpose_conjg_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2008-03-30 14:23:55 UTC
Subject: Bug 35740

Author: pault
Date: Sun Mar 30 14:23:10 2008
New Revision: 133730

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133730
Log:
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.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/transpose_conjg_1.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/resolve.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 6 Paul Thomas 2008-03-30 14:25:47 UTC
Fixed on trunk and 4.3.  Thanks for the report.

Paul