public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma
@ 2011-03-11  0:42 wschmidt at gcc dot gnu.org
  2011-03-11  0:56 ` [Bug tree-optimization/48067] " wschmidt at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2011-03-11  0:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

           Summary: FMA with no add operand produced by convert_mul_to_fma
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: wschmidt@gcc.gnu.org
                CC: rguenth@gcc.gnu.org, bergner@gcc.gnu.org,
                    pthaugen@gcc.gnu.org


There is a latent bug in tree-ssa-math-ops.c: convert_mul_to_fma.  This is
exposed when building SPEC cpu2000 benchmark 191.fma3d for
branches/ibm/gcc-4_5-branch, but does not currently reproduce on mainline or
fsf 4.5.

Prior to the widening_mul pass, the gimple contains the following (stripped of
unrelated statements):

  c12_7 = D.743_5 * cim_6(D);
  d12_8 = -c12_7;
  D.745_11 = c12_7 - d12_8;

The FMA transform produces this:

  D.768_8 = -D.743_5;
  D.767_20 = D.768_8 * cim_6(D) + ;
  D.745_11 = D.743_5 * cim_6(D) + D.767_20;

The second instruction is a ternary op with a null rhs3 operand.  This causes a
segv in the verify_ssa code following this pass.

convert_mul_to_fma has two loops over the immediate uses of mul_result (c12_7
in this case).  In the first loop, if a use is found to be a NEGATE_EXPR, it is
only processed if it has a single immediate use, which must be a PLUS_EXPR or a
MINUS_EXPR.  The second loop assumes this still holds.  Unfortunately, this
case demonstrates that it is possible for the assumption to be violated.

The first pass through the second loop processes the assignment to D.745_11
first, and converts it to an FMA:

  D.767_20 = -d12_8;
  D.745_11 = D.743_5 * cim_6(D) + D.767_20;

Note that this has removed the original use of d12_8 in a MINUS_EXPR, and
replaced it with a new use in a NEGATE_EXPR.  Now the statement

  d12_8 = -c12_7;

no longer satisfies the rule that its single use is in a PLUS_EXPR or a
MINUS_EXPR.  It's now part of a NEGATE_EXPR that can't be converted into an
FMA.

I believe the right thing to do here is probably to check for neguse_stmt still
being either a PLUS_EXPR or a MINUS_EXPR after the call to single_imm_use in
the second loop.  If not, avoid replacing the original use_stmt with
neguse_stmt and just continue to the next use.  But I'll defer to those with
more knowledge of the code.

(As a side note, the first loop over immediate uses manipulates a "negate_p"
local var that doesn't appear to have any effect.  The second loop has its own
copy of negate_p.  Looks like something left over from an earlier design?)

The procedure where the above occurs in 191.fma3d is:

      SUBROUTINE MATERIAL_22_INTEGRATION                                      
&
     &          (                                                             
&
     &          STRESS,A,B,Strain_A,Strain_B,Strain_C,Akk,                    
&
     &          DTnext,Drr,Dss,Drs,MatID                                      
&
     &          )
      REAL(KIND(0D0))                                                         
&
     &          STRESS(3),A(2),B(2)
      IF (PAB .GT. 0.0) THEN
        C12 = C1*C2 * Cim
        D12 = -C12
        IF (SMD .EQ. 0.0) THEN
        ENDIF
        STRESS(3) = STRESS(3) + (Shear * (C12 - D12))
      ENDIF
      IF (Akk .LE. Afc) THEN
      ENDIF
      END


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
@ 2011-03-11  0:56 ` wschmidt at gcc dot gnu.org
  2011-03-11 10:17 ` [Bug tree-optimization/48067] [4.6 Regression] " rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2011-03-11  0:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

--- Comment #1 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2011-03-11 00:55:30 UTC ---
Created attachment 23620
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23620
Failing subroutine from 191.fma3d

Sorry the subroutine was mangled in the comments.  Here's a clean copy.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
  2011-03-11  0:56 ` [Bug tree-optimization/48067] " wschmidt at gcc dot gnu.org
@ 2011-03-11 10:17 ` rguenth at gcc dot gnu.org
  2011-03-11 14:50 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-11 10:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|powerpc64-linux             |powerpc64-linux, x86_64-*-*
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.03.11 10:17:47
               Host|powerpc64-linux             |
         AssignedTo|unassigned at gcc dot       |rguenth at gcc dot gnu.org
                   |gnu.org                     |
   Target Milestone|---                         |4.6.0
            Summary|FMA with no add operand     |[4.6 Regression] FMA with
                   |produced by                 |no add operand produced by
                   |convert_mul_to_fma          |convert_mul_to_fma
     Ever Confirmed|0                           |1
              Build|powerpc64-linux             |

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-11 10:17:47 UTC ---
Reproduces on trunk/x86_64 with

  -O2 -ffast-math -mfma4 -fno-tree-forwprop -fno-tree-reassoc

on trunk both forwprop and reassoc change

  d12_8 = -c12_7;
  D.745_11 = c12_7 - d12_8;

to

  D.745_11 = c12_7 + c_12_7;

making the issue latent.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
  2011-03-11  0:56 ` [Bug tree-optimization/48067] " wschmidt at gcc dot gnu.org
  2011-03-11 10:17 ` [Bug tree-optimization/48067] [4.6 Regression] " rguenth at gcc dot gnu.org
@ 2011-03-11 14:50 ` rguenth at gcc dot gnu.org
  2011-03-11 16:36 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-11 14:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-11 14:50:13 UTC ---
(In reply to comment #2)
> Reproduces on trunk/x86_64 with
> 
>   -O2 -ffast-math -mfma4 -fno-tree-forwprop -fno-tree-reassoc
> 
> on trunk both forwprop and reassoc change
> 
>   d12_8 = -c12_7;
>   D.745_11 = c12_7 - d12_8;
> 
> to
> 
>   D.745_11 = c12_7 + c_12_7;
> 
> making the issue latent.

C testcase with the above flags:

float
foo (float x, float cim)
{
  float c = x * cim;
  float d = -c;
  return c - d;
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-03-11 14:50 ` rguenth at gcc dot gnu.org
@ 2011-03-11 16:36 ` rguenth at gcc dot gnu.org
  2011-03-11 16:37 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-11 16:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-11 16:36:35 UTC ---
Fixed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-03-11 16:36 ` rguenth at gcc dot gnu.org
@ 2011-03-11 16:37 ` rguenth at gcc dot gnu.org
  2011-03-11 18:46 ` wschmidt at gcc dot gnu.org
  2011-03-11 18:53 ` wschmidt at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-11 16:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-11 16:36:22 UTC ---
Author: rguenth
Date: Fri Mar 11 16:36:16 2011
New Revision: 170877

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170877
Log:
2011-03-11  Richard Guenther  <rguenther@suse.de>

    PR tree-optimization/48067
    * tree-ssa-math-opts.c (convert_mult_to_fma): Verify the
    multiplication result will be only used once on the target
    stmt.

    * gcc.dg/pr48067.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/pr48067.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-math-opts.c


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-03-11 16:37 ` rguenth at gcc dot gnu.org
@ 2011-03-11 18:46 ` wschmidt at gcc dot gnu.org
  2011-03-11 18:53 ` wschmidt at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2011-03-11 18:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

--- Comment #6 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2011-03-11 18:46:27 UTC ---
Author: wschmidt
Date: Fri Mar 11 18:46:24 2011
New Revision: 170882

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=170882
Log:
Backport PR tree-optimization/48067 from mainline

Added:
    branches/ibm/gcc-4_5-branch/gcc/testsuite/gcc.dg/pr48067.c
Modified:
    branches/ibm/gcc-4_5-branch/gcc/ChangeLog.ibm
    branches/ibm/gcc-4_5-branch/gcc/tree-ssa-math-opts.c


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/48067] [4.6 Regression] FMA with no add operand produced by convert_mul_to_fma
  2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-03-11 18:46 ` wschmidt at gcc dot gnu.org
@ 2011-03-11 18:53 ` wschmidt at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2011-03-11 18:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48067

--- Comment #7 from William J. Schmidt <wschmidt at gcc dot gnu.org> 2011-03-11 18:52:45 UTC ---
I verified this on branches/ibm/gcc-4_5-branch, and it regtests successfully
there as well.  Thanks for the quick turnaround!


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-11 18:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11  0:42 [Bug tree-optimization/48067] New: FMA with no add operand produced by convert_mul_to_fma wschmidt at gcc dot gnu.org
2011-03-11  0:56 ` [Bug tree-optimization/48067] " wschmidt at gcc dot gnu.org
2011-03-11 10:17 ` [Bug tree-optimization/48067] [4.6 Regression] " rguenth at gcc dot gnu.org
2011-03-11 14:50 ` rguenth at gcc dot gnu.org
2011-03-11 16:36 ` rguenth at gcc dot gnu.org
2011-03-11 16:37 ` rguenth at gcc dot gnu.org
2011-03-11 18:46 ` wschmidt at gcc dot gnu.org
2011-03-11 18:53 ` wschmidt 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).