public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug
@ 2013-01-17 8:40 t_nissie at yahoo dot co.jp
2013-01-17 8:52 ` [Bug middle-end/56015] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly pinskia at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: t_nissie at yahoo dot co.jp @ 2013-01-17 8:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Bug #: 56015
Summary: Option -ffast-math reveals i*(a+bi) -> -b-bi, a
complex multiplication bug
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: t_nissie@yahoo.co.jp
With gfortran, optimization option "-O3 -ffast-math", more
precisely "-O3 -funsafe-math-optimizations -ffinite-math-only"
reveals a complex multiplication bug of
i*(a+bi) =
Good: -b+ai
Bug: -b-bi
Source:
! multiplyi.f -*-f90-*-
!!
program multiplyi
implicit none
complex*16 p(10)
p(:) = (0.1d0, 0.2d0)
p(:) = (0.0d0, 1.0d0) * p(:)
write(6,'(2f5.1)') p(1)
end program multiplyi
Compilation and execution:
$ gfortran --version
GNU Fortran (GCC) 4.7.2
$ gfortran -ffree-form -O3 -o nofast-math multiplyi.f && ./nofast-math
-0.2 0.1
$ gfortran -ffree-form -O3 -ffast-math -o fast-math multiplyi.f && ./fast-math
-0.2 -0.2
Details:
* I could reproduce this bug with gcc-4.4.6, 4.6.3, and 4.7.2.
* I could reproduce it on Intel Core i5 and Xeon5650 (64bit)
and VIA C7-M (32bit).
* To reproduce this bug, the variable p(10) should not be an
array in 4.6.3, but it should be an array in 4.7.2.
Tank you for your constant efforts on gfortran,
Takeshi
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
@ 2013-01-17 8:52 ` pinskia at gcc dot gnu.org
2013-01-17 10:30 ` [Bug middle-end/56015] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-01-17 8:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-01-17
Component|fortran |middle-end
Summary|Option -ffast-math reveals |expand expands p[9] =
|i*(a+bi) -> -b-bi, a |COMPLEX_EXPR
|complex multiplication bug |<-IMAGPART_EXPR <p[9]>,
| |REALPART_EXPR <p[9]>>;
| |incorrectly.
Ever Confirmed|0 |1
Known to fail|4.4.6, 4.6.3, 4.7.2 |4.3.5, 4.4.5, 4.8.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-01-17 08:52:25 UTC ---
Actually it is not the multiplication that goes wrong. In fact the code looks
correct before expand. Turning off TER (-fno-tree-ter) will work around this
expand issue though.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7/4.8 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
2013-01-17 8:52 ` [Bug middle-end/56015] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly pinskia at gcc dot gnu.org
@ 2013-01-17 10:30 ` jakub at gcc dot gnu.org
2013-01-17 10:31 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-17 10:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |jakub at gcc dot gnu.org
Known to work| |4.1.2
AssignedTo|unassigned at gcc dot |jakub at gcc dot gnu.org
|gnu.org |
Target Milestone|--- |4.6.4
Summary|expand expands p[9] = |[4.6/4.7/4.8 Regression]
|COMPLEX_EXPR |expand expands p[9] =
|<-IMAGPART_EXPR <p[9]>, |COMPLEX_EXPR
|REALPART_EXPR <p[9]>>; |<-IMAGPART_EXPR <p[9]>,
|incorrectly. |REALPART_EXPR <p[9]>>;
| |incorrectly.
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-17 10:30:11 UTC ---
Works correctly with 4.1.2, where we had
CR.108 = REALPART_EXPR <p[0]>;
REALPART_EXPR <p[0]> = -IMAGPART_EXPR <p[0]>;
IMAGPART_EXPR <p[0]> = CR.108;
in the *.optimized dump. Thus a regression.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7/4.8 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
2013-01-17 8:52 ` [Bug middle-end/56015] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly pinskia at gcc dot gnu.org
2013-01-17 10:30 ` [Bug middle-end/56015] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
@ 2013-01-17 10:31 ` jakub at gcc dot gnu.org
2013-01-17 10:48 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-17 10:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-17 10:31:08 UTC ---
Created attachment 29189
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29189
gcc48-pr56015.patch
Untested fix.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7/4.8 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (2 preceding siblings ...)
2013-01-17 10:31 ` jakub at gcc dot gnu.org
@ 2013-01-17 10:48 ` rguenth at gcc dot gnu.org
2013-01-17 11:58 ` t_nissie at yahoo dot co.jp
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-01-17 10:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> 2013-01-17 10:48:40 UTC ---
Hmm, I wonder if it isn't better to disable TER for these cases. We might
run into similar issues with other loads (BIT_FIELD_REF and vectors for
example).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7/4.8 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (3 preceding siblings ...)
2013-01-17 10:48 ` rguenth at gcc dot gnu.org
@ 2013-01-17 11:58 ` t_nissie at yahoo dot co.jp
2013-01-18 17:15 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: t_nissie at yahoo dot co.jp @ 2013-01-17 11:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
--- Comment #5 from Takeshi Nishimatsu <t_nissie at yahoo dot co.jp> 2013-01-17 11:58:24 UTC ---
(In reply to comment #3)
> Created attachment 29189 [details]
> gcc48-pr56015.patch
>
> Untested fix.
Thank you for your fix.
I add one more test multiplying -i.
program pr56015
implicit none
complex*16 m(10),p(10)
m(:) = (0.3d0, 0.4d0)
m(:) = (0.0d0,-1.0d0) * m(:)
call bar (m)
p(:) = (0.1d0, 0.2d0)
p(:) = (0.0d0, 1.0d0) * p(:)
call foo (p)
contains
subroutine bar (m)
complex*16 m(10)
if (any (m .ne. ( 0.4d0,-0.3d0))) call abort
end subroutine
subroutine foo (p)
complex*16 p(10)
if (any (p .ne. (-0.2d0, 0.1d0))) call abort
end subroutine
end program pr56015
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7/4.8 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (4 preceding siblings ...)
2013-01-17 11:58 ` t_nissie at yahoo dot co.jp
@ 2013-01-18 17:15 ` jakub at gcc dot gnu.org
2013-01-18 17:26 ` [Bug middle-end/56015] [4.6/4.7 " jakub at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-18 17:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-18 17:15:17 UTC ---
Author: jakub
Date: Fri Jan 18 17:15:07 2013
New Revision: 195301
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195301
Log:
PR middle-end/56015
* expr.c (expand_expr_real_2) <case COMPLEX_EXPR>: Handle
the case where writing real complex part of target modifies
op1.
* gfortran.dg/pr56015.f90: New test.
Added:
trunk/gcc/testsuite/gfortran.dg/pr56015.f90
Modified:
trunk/gcc/ChangeLog
trunk/gcc/expr.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (5 preceding siblings ...)
2013-01-18 17:15 ` jakub at gcc dot gnu.org
@ 2013-01-18 17:26 ` jakub at gcc dot gnu.org
2013-02-01 14:11 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-18 17:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.8.0
Summary|[4.6/4.7/4.8 Regression] |[4.6/4.7 Regression] expand
|expand expands p[9] = |expands p[9] = COMPLEX_EXPR
|COMPLEX_EXPR |<-IMAGPART_EXPR <p[9]>,
|<-IMAGPART_EXPR <p[9]>, |REALPART_EXPR <p[9]>>;
|REALPART_EXPR <p[9]>>; |incorrectly.
|incorrectly. |
Known to fail|4.8.0 |
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-18 17:25:46 UTC ---
Fixed on the trunk so far.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6/4.7 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (6 preceding siblings ...)
2013-01-18 17:26 ` [Bug middle-end/56015] [4.6/4.7 " jakub at gcc dot gnu.org
@ 2013-02-01 14:11 ` jakub at gcc dot gnu.org
2013-02-01 14:32 ` [Bug middle-end/56015] [4.6 " jakub at gcc dot gnu.org
2013-04-03 18:20 ` jakub at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-01 14:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-01 14:11:03 UTC ---
Author: jakub
Date: Fri Feb 1 14:10:48 2013
New Revision: 195657
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195657
Log:
Backported from mainline
2013-01-18 Jakub Jelinek <jakub@redhat.com>
PR middle-end/56015
* expr.c (expand_expr_real_2) <case COMPLEX_EXPR>: Handle
the case where writing real complex part of target modifies
op1.
* gfortran.dg/pr56015.f90: New test.
Added:
branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/pr56015.f90
Modified:
branches/gcc-4_7-branch/gcc/ChangeLog
branches/gcc-4_7-branch/gcc/expr.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (7 preceding siblings ...)
2013-02-01 14:11 ` jakub at gcc dot gnu.org
@ 2013-02-01 14:32 ` jakub at gcc dot gnu.org
2013-04-03 18:20 ` jakub at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-01 14:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.7.3
Summary|[4.6/4.7 Regression] expand |[4.6 Regression] expand
|expands p[9] = COMPLEX_EXPR |expands p[9] = COMPLEX_EXPR
|<-IMAGPART_EXPR <p[9]>, |<-IMAGPART_EXPR <p[9]>,
|REALPART_EXPR <p[9]>>; |REALPART_EXPR <p[9]>>;
|incorrectly. |incorrectly.
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-01 14:32:05 UTC ---
Fixed for 4.7.3+ too.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug middle-end/56015] [4.6 Regression] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly.
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
` (8 preceding siblings ...)
2013-02-01 14:32 ` [Bug middle-end/56015] [4.6 " jakub at gcc dot gnu.org
@ 2013-04-03 18:20 ` jakub at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-03 18:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56015
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-03 18:20:25 UTC ---
Author: jakub
Date: Wed Apr 3 18:01:51 2013
New Revision: 197448
URL: http://gcc.gnu.org/viewcvs?rev=197448&root=gcc&view=rev
Log:
Backported from mainline
2013-01-18 Jakub Jelinek <jakub@redhat.com>
PR middle-end/56015
* expr.c (expand_expr_real_2) <case COMPLEX_EXPR>: Handle
the case where writing real complex part of target modifies
op1.
* gfortran.dg/pr56015.f90: New test.
Added:
branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/pr56015.f90
Modified:
branches/gcc-4_6-branch/gcc/ChangeLog
branches/gcc-4_6-branch/gcc/expr.c
branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-04-03 18:20 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-17 8:40 [Bug fortran/56015] New: Option -ffast-math reveals i*(a+bi) -> -b-bi, a complex multiplication bug t_nissie at yahoo dot co.jp
2013-01-17 8:52 ` [Bug middle-end/56015] expand expands p[9] = COMPLEX_EXPR <-IMAGPART_EXPR <p[9]>, REALPART_EXPR <p[9]>>; incorrectly pinskia at gcc dot gnu.org
2013-01-17 10:30 ` [Bug middle-end/56015] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
2013-01-17 10:31 ` jakub at gcc dot gnu.org
2013-01-17 10:48 ` rguenth at gcc dot gnu.org
2013-01-17 11:58 ` t_nissie at yahoo dot co.jp
2013-01-18 17:15 ` jakub at gcc dot gnu.org
2013-01-18 17:26 ` [Bug middle-end/56015] [4.6/4.7 " jakub at gcc dot gnu.org
2013-02-01 14:11 ` jakub at gcc dot gnu.org
2013-02-01 14:32 ` [Bug middle-end/56015] [4.6 " jakub at gcc dot gnu.org
2013-04-03 18:20 ` jakub at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).