public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/31029]  New: missed otimization
@ 2007-03-02 19:36 jv244 at cam dot ac dot uk
  2007-03-02 20:04 ` [Bug tree-optimization/31029] missed optimization pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-03-02 19:36 UTC (permalink / raw)
  To: gcc-bugs

the following is tiny missed optimization, as it fails to link at -O3

read(5,*) igmin
DO ig=igmin,0
   ig2=1-ig
   if (ig.EQ.ig2) CALL link_error()
ENDDO
END

since ig can only have values in the interval [-huge,0], ig2 can only have
values in [1,huge] and so ig can never be equal to ig2. Code similar to this
appears in PR 31021


-- 
           Summary: missed otimization
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jv244 at cam dot ac dot uk


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


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

* [Bug tree-optimization/31029] missed optimization
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
@ 2007-03-02 20:04 ` pinskia at gcc dot gnu dot org
  2007-05-06 15:26 ` jv244 at cam dot ac dot uk
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-02 20:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-03-02 20:04 -------


*** This bug has been marked as a duplicate of 30965 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

* [Bug tree-optimization/31029] missed optimization
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
  2007-03-02 20:04 ` [Bug tree-optimization/31029] missed optimization pinskia at gcc dot gnu dot org
@ 2007-05-06 15:26 ` jv244 at cam dot ac dot uk
  2007-06-20 21:53 ` fxcoudert at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-05-06 15:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jv244 at cam dot ac dot uk  2007-05-06 16:26 -------
(In reply to comment #1)
> 
> *** This bug has been marked as a duplicate of 30965 ***
> 

Still fails for me with today's gfortran:
> gfortran -O3 mytest.f90
/tmp/cc6sfSVv.o(.text+0x9f): In function `MAIN__':
: undefined reference to `link_error_'

so I doubt this is a strict duplicate of PR 30965


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


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


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

* [Bug tree-optimization/31029] missed optimization
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
  2007-03-02 20:04 ` [Bug tree-optimization/31029] missed optimization pinskia at gcc dot gnu dot org
  2007-05-06 15:26 ` jv244 at cam dot ac dot uk
@ 2007-06-20 21:53 ` fxcoudert at gcc dot gnu dot org
  2007-06-21  4:08 ` jv244 at cam dot ac dot uk
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-06-20 21:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-06-20 21:53 -------
(In reply to comment #0)
> DO ig=igmin,0
>    ig2=1-ig
>    if (ig.EQ.ig2) CALL link_error()
> ENDDO
> END

If igmin is -huge(0), (1-ig) can wrap, so ig2 might eventually be equal to ig,
no? (although I agree for wrapping arithmetic, it will never be the case)


-- 


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


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

* [Bug tree-optimization/31029] missed optimization
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (2 preceding siblings ...)
  2007-06-20 21:53 ` fxcoudert at gcc dot gnu dot org
@ 2007-06-21  4:08 ` jv244 at cam dot ac dot uk
  2008-08-28 15:41 ` jv244 at cam dot ac dot uk
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jv244 at cam dot ac dot uk @ 2007-06-21  4:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jv244 at cam dot ac dot uk  2007-06-21 04:08 -------
> If igmin is -huge(0), (1-ig) can wrap, so ig2 might eventually be equal to ig,
> no? (although I agree for wrapping arithmetic, it will never be the case)

in Fortran 1-ig can't overflow (unless the program is undefined), but I'm sure
you know...


-- 


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


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

* [Bug tree-optimization/31029] missed optimization
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (3 preceding siblings ...)
  2007-06-21  4:08 ` jv244 at cam dot ac dot uk
@ 2008-08-28 15:41 ` jv244 at cam dot ac dot uk
  2008-11-02 16:09 ` [Bug middle-end/31029] Fold does not fold a + C == a rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jv244 at cam dot ac dot uk @ 2008-08-28 15:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jv244 at cam dot ac dot uk  2008-08-28 15:40 -------
current trunk still doesn't remove the if statement, despite the fact that it
could.


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
      Known to fail|                            |4.3.0 4.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2008-08-28 15:40:02
               date|                            |


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


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

* [Bug middle-end/31029] Fold does not fold a + C == a
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (4 preceding siblings ...)
  2008-08-28 15:41 ` jv244 at cam dot ac dot uk
@ 2008-11-02 16:09 ` rguenth at gcc dot gnu dot org
  2008-11-02 18:25 ` [Bug middle-end/31029] Fold does not fold C - a " rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-02 16:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2008-11-02 16:08 -------
This is because fold doesn't fold ig_1 == 1 - ig_1 to a constant.  Which is
just because it doesn't handle this canonical form but expects X +- CST always.

Fixing that makes the first forwprop pass optimize the comparison to false.

I have a patch, queued for 4.5.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
           Severity|normal                      |enhancement
             Status|NEW                         |ASSIGNED
          Component|tree-optimization           |middle-end
   Last reconfirmed|2008-08-28 15:40:02         |2008-11-02 16:08:21
               date|                            |
            Summary|missed optimization         |Fold does not fold a + C ==
                   |                            |a


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


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

* [Bug middle-end/31029] Fold does not fold C - a == a
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (5 preceding siblings ...)
  2008-11-02 16:09 ` [Bug middle-end/31029] Fold does not fold a + C == a rguenth at gcc dot gnu dot org
@ 2008-11-02 18:25 ` rguenth at gcc dot gnu dot org
  2008-11-11  6:01 ` jv244 at cam dot ac dot uk
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-02 18:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2008-11-02 18:23 -------
Actually we can fold C - a == a only for odd C.
But more generally a +- b == a to b == 0.


-- 


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


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

* [Bug middle-end/31029] Fold does not fold C - a == a
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (6 preceding siblings ...)
  2008-11-02 18:25 ` [Bug middle-end/31029] Fold does not fold C - a " rguenth at gcc dot gnu dot org
@ 2008-11-11  6:01 ` jv244 at cam dot ac dot uk
  2009-03-31 14:28 ` rguenth at gcc dot gnu dot org
  2009-03-31 14:29 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jv244 at cam dot ac dot uk @ 2008-11-11  6:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jv244 at cam dot ac dot uk  2008-11-11 06:00 -------
(In reply to comment #7)
> Actually we can fold C - a == a only for odd C.
> But more generally a +- b == a to b == 0.
> 
right... that works as well for this optimization. 

The original argument was on the range of a and thus C-a. Which allows also
folding C - a == a for non-odd values of C.


-- 


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


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

* [Bug middle-end/31029] Fold does not fold C - a == a
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (7 preceding siblings ...)
  2008-11-11  6:01 ` jv244 at cam dot ac dot uk
@ 2009-03-31 14:28 ` rguenth at gcc dot gnu dot org
  2009-03-31 14:29 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-31 14:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2009-03-31 14:28 -------
Subject: Bug 31029

Author: rguenth
Date: Tue Mar 31 14:28:16 2009
New Revision: 145345

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

        PR middle-end/31029
        * fold-const.c (fold_binary): Fold X +- Y CMP X to Y CMP 0 for
        equality comparisons.  Fold C - X CMP X if C % 2 == 1.

        * gcc.dg/fold-compare-4.c: New testcase.
        * gcc.dg/fold-compare-5.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/fold-compare-4.c
    trunk/gcc/testsuite/gcc.dg/fold-compare-5.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/31029] Fold does not fold C - a == a
  2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
                   ` (8 preceding siblings ...)
  2009-03-31 14:28 ` rguenth at gcc dot gnu dot org
@ 2009-03-31 14:29 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-31 14:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2009-03-31 14:28 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

end of thread, other threads:[~2009-03-31 14:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-02 19:36 [Bug tree-optimization/31029] New: missed otimization jv244 at cam dot ac dot uk
2007-03-02 20:04 ` [Bug tree-optimization/31029] missed optimization pinskia at gcc dot gnu dot org
2007-05-06 15:26 ` jv244 at cam dot ac dot uk
2007-06-20 21:53 ` fxcoudert at gcc dot gnu dot org
2007-06-21  4:08 ` jv244 at cam dot ac dot uk
2008-08-28 15:41 ` jv244 at cam dot ac dot uk
2008-11-02 16:09 ` [Bug middle-end/31029] Fold does not fold a + C == a rguenth at gcc dot gnu dot org
2008-11-02 18:25 ` [Bug middle-end/31029] Fold does not fold C - a " rguenth at gcc dot gnu dot org
2008-11-11  6:01 ` jv244 at cam dot ac dot uk
2009-03-31 14:28 ` rguenth at gcc dot gnu dot org
2009-03-31 14:29 ` rguenth at gcc dot gnu dot 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).