public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/40052]  New: missed optimizations on logical types: (x | 1) --> 1
@ 2009-05-06 23:02 matz at gcc dot gnu dot org
  2009-05-07  8:58 ` [Bug tree-optimization/40052] missed optimizations on (extended) " rguenth at gcc dot gnu dot org
  2009-05-07  9:36 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 6+ messages in thread
From: matz at gcc dot gnu dot org @ 2009-05-06 23:02 UTC (permalink / raw)
  To: gcc-bugs

The testcase from PR40021:
 http://gcc.gnu.org/bugzilla/attachment.cgi?id=17800&action=view
shows a current problem in optimizing away logical operations on logical
(boolean) types, like "x | 1" --> "1".  This folding is done in some contexts,
and not in others.  In particular the testcase
 (with -m32 -O2 -ftree-vectorize -msse2 -mfpmath=sse -ffast-math )
leaves this until expand (it's generated quite early already, so there
are multiple possibilities to fold it):

  D.1650_109 = D.1648_107 | 1;
  if (D.1650_109 != 0)
    goto <bb 6>;
  else
    goto <bb 5>;

Richi already fiddled a bit with this, so CCing him.


-- 
           Summary: missed optimizations on logical types: (x | 1) --> 1
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matz at gcc dot gnu dot org
  GCC host triplet: x86_64-unknown-linux-gnu


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


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

* [Bug tree-optimization/40052] missed optimizations on (extended) logical types: (x | 1) --> 1
  2009-05-06 23:02 [Bug tree-optimization/40052] New: missed optimizations on logical types: (x | 1) --> 1 matz at gcc dot gnu dot org
@ 2009-05-07  8:58 ` rguenth at gcc dot gnu dot org
  2009-05-07  9:36 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-07  8:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-05-07 08:58 -------
C testcase:

int foo(_Bool b)
{
  return b | 1;
}

int bar(_Bool b)
{
  return b & -2;
}

should both be folded to return a constant but instead are never optimized,
not even at RTL level.

Due to C semantics we get

  return (int) b | 1;

and

  return (int) b & -2;

here.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-07 08:58:29
               date|                            |
            Summary|missed optimizations on     |missed optimizations on
                   |logical types: (x | 1) --> 1|(extended) logical types: (x
                   |                            || 1) --> 1


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


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

* [Bug tree-optimization/40052] missed optimizations on (extended) logical types: (x | 1) --> 1
  2009-05-06 23:02 [Bug tree-optimization/40052] New: missed optimizations on logical types: (x | 1) --> 1 matz at gcc dot gnu dot org
  2009-05-07  8:58 ` [Bug tree-optimization/40052] missed optimizations on (extended) " rguenth at gcc dot gnu dot org
@ 2009-05-07  9:36 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-07  9:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-05-07 09:36 -------
Of course this only works if logicals are zero-extended.

We manage to fold

int foo(unsigned char b)
{
  return b | 0xff;
}

but not

int bar(unsigned char b)
{
  return b & (~0 << 8);
}

appearantly because the C FE for the former generates (int) (b | 255)
because of some premature optimization in build_binary_op.

We still do not fold

int foo(unsigned char b)
{
  return b | 0xfff;
}


-- 


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


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

* [Bug tree-optimization/40052] missed optimizations on (extended) logical types: (x | 1) --> 1
       [not found] <bug-40052-4@http.gcc.gnu.org/bugzilla/>
  2011-04-27 17:48 ` matt at use dot net
  2011-04-28 10:01 ` rguenth at gcc dot gnu.org
@ 2011-04-28 10:07 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-28 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-28 09:55:46 UTC ---
Author: rguenth
Date: Thu Apr 28 09:55:41 2011
New Revision: 173064

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

    PR tree-optimization/40052
    PR tree-optimization/15347
    * gcc.dg/tree-ssa/vrp57.c: New testcase.
    * gcc.dg/pr15347.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/pr15347.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/vrp57.c
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/40052] missed optimizations on (extended) logical types: (x | 1) --> 1
       [not found] <bug-40052-4@http.gcc.gnu.org/bugzilla/>
  2011-04-27 17:48 ` matt at use dot net
@ 2011-04-28 10:01 ` rguenth at gcc dot gnu.org
  2011-04-28 10:07 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-28 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-28 09:56:24 UTC ---
Fixed.  Thanks for noticing.


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

* [Bug tree-optimization/40052] missed optimizations on (extended) logical types: (x | 1) --> 1
       [not found] <bug-40052-4@http.gcc.gnu.org/bugzilla/>
@ 2011-04-27 17:48 ` matt at use dot net
  2011-04-28 10:01 ` rguenth at gcc dot gnu.org
  2011-04-28 10:07 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 6+ messages in thread
From: matt at use dot net @ 2011-04-27 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

Matt Hargett <matt at use dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matt at use dot net

--- Comment #3 from Matt Hargett <matt at use dot net> 2011-04-27 17:47:48 UTC ---
I just tested this with 4.6.0 and all of the below cases appear to fold
correctly at -O2. Can this be marked as resolved?


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

end of thread, other threads:[~2011-04-28 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-06 23:02 [Bug tree-optimization/40052] New: missed optimizations on logical types: (x | 1) --> 1 matz at gcc dot gnu dot org
2009-05-07  8:58 ` [Bug tree-optimization/40052] missed optimizations on (extended) " rguenth at gcc dot gnu dot org
2009-05-07  9:36 ` rguenth at gcc dot gnu dot org
     [not found] <bug-40052-4@http.gcc.gnu.org/bugzilla/>
2011-04-27 17:48 ` matt at use dot net
2011-04-28 10:01 ` rguenth at gcc dot gnu.org
2011-04-28 10:07 ` rguenth 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).