public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16856] New: Missed optimisation opportunity with -O2
@ 2004-08-02 21:38 ralph at gcc dot gnu dot org
  2004-08-02 21:57 ` [Bug tree-optimization/16856] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 3+ messages in thread
From: ralph at gcc dot gnu dot org @ 2004-08-02 21:38 UTC (permalink / raw)
  To: gcc-bugs

The following code is not optimised optimally with -O2.  The two branches of the
conditional have the same effect, so the conditional can be removed entirely.  

The conditional is removed with -Os, so gcc is capable of carrying out the
optimisation; it just isn't happening at -O2.

$ cat temp.c
static int bar;
static long baz;
 
int foo (_Bool x)
{
    int y;
    if (x) {
        ++baz;
        y = bar;
    }
    else {
        y = bar;
        ++baz;
    }
    return y;
}


$ gcc35 -S -O2 -fomit-frame-pointer -o temp-O2.s temp.c 
$ cat temp-O2.s
...
foo:
        cmpb    $0, 4(%esp)
        je      .L2
        incl    baz
        movl    bar, %eax
        ret
        .p2align 2,,3
.L2:
        movl    bar, %eax
        incl    baz
        ret
...
        .ident  "GCC: (GNU) 3.5.0 20040715 (Red Hat 3.5.0-0.7)"

-- 
           Summary: Missed optimisation opportunity with -O2
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralph at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug tree-optimization/16856] Missed optimisation opportunity with -O2
  2004-08-02 21:38 [Bug c/16856] New: Missed optimisation opportunity with -O2 ralph at gcc dot gnu dot org
@ 2004-08-02 21:57 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-02 21:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-02 21:57 -------
Confirmed, related to PR 15559.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
          Component|c                           |tree-optimization
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-08-02 21:57:56
               date|                            |


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


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

* [Bug tree-optimization/16856] Missed optimisation opportunity with -O2
       [not found] <bug-16856-4@http.gcc.gnu.org/bugzilla/>
@ 2011-05-22 15:44 ` steven at gcc dot gnu.org
  0 siblings, 0 replies; 3+ messages in thread
From: steven at gcc dot gnu.org @ 2011-05-22 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |steven at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #2 from Steven Bosscher <steven at gcc dot gnu.org> 2011-05-22 15:24:48 UTC ---
$ cat t.c
static int bar;
static long baz;

int foo (_Bool x)
{
  int y;
  if (x) {
      ++baz;
      y = bar;
  }
  else {
      y = bar;
      ++baz;
  }
  return y;
}

$ ./cc1 -quiet -m32 -O2 t.c -fdump-tree-optimized
$ cat t.c.143t.optimized 

;; Function foo (foo)

foo (_Bool x)
{
  long int baz.1;
  long int baz.0;

<bb 2>:
  if (x_2(D) != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

<bb 3>:
  baz.0_3 = baz;
  baz.1_4 = baz.0_3 + 1;
  baz = baz.1_4;
  goto <bb 5>;

<bb 4>:
  baz.0_7 = baz;
  baz.1_8 = baz.0_7 + 1;
  baz = baz.1_8;

<bb 5>:
  return 0;

}


$ cat t.s
    .file    "t.c"
    .text
    .p2align 4,,15
    .globl    foo
    .type    foo, @function
foo:
.LFB0:
    .cfi_startproc
    addl    $1, baz
    xorl    %eax, %eax
    ret
    .cfi_endproc
.LFE0:
    .size    foo, .-foo
    .local    baz
    .comm    baz,4,4
    .ident    "GCC: (GNU) 4.6.0 20110312 (experimental) [trunk revision
170907]"
    .section    .note.GNU-stack,"",@progbits


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

end of thread, other threads:[~2011-05-22 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-02 21:38 [Bug c/16856] New: Missed optimisation opportunity with -O2 ralph at gcc dot gnu dot org
2004-08-02 21:57 ` [Bug tree-optimization/16856] " pinskia at gcc dot gnu dot org
     [not found] <bug-16856-4@http.gcc.gnu.org/bugzilla/>
2011-05-22 15:44 ` steven 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).