public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42494]  New: Regression on dead-code-elimination: GCC 4.2.1 generates better code than 4.4.0
@ 2009-12-25  5:42 sliao at google dot com
  2009-12-29 10:35 ` [Bug c/42494] [4.4 only] " ramana at gcc dot gnu dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 26+ messages in thread
From: sliao at google dot com @ 2009-12-25  5:42 UTC (permalink / raw)
  To: gcc-bugs

For the following code:

extern void func();
extern char outbuf[];
extern int outcnt;
extern int bool_var;
void test ()
{
 char flags;
 flags = 0;
 outcnt = 0;
 if (outcnt == 1) func ();
 if (outcnt == 1) func ();
 if (outcnt == 1) func ();
 if (bool_var) flags = 2;
 outbuf[outcnt] = flags;
 if (outcnt == 1) func ();
}

I found that GCC 4.4.0 generates the following code:

       .code   16
       .file   "outcnt.c"
       .text
       .align  2
       .global test
       .code   16
       .thumb_func
       .type   test, %function
test:
       push    {r4, lr}
       ldr     r3, .L7
       mov     r2, #0
       str     r2, [r3]
       ldr     r3, .L7+4
       mov     r2, #2
       ldr     r3, [r3]
       cmp     r3, #0
       bne     .L3
       mov     r2, #0
.L3:
       ldr     r3, .L7
       ldr     r1, .L7+8
       ldr     r3, [r3]
       strb    r2, [r1, r3]
       cmp     r3, #1
       bne     .L5
       bl      func
.L5:
       @ sp needed for prologue
       pop     {r4, pc}
.L8:
       .align  2
.L7:
       .word   outcnt
       .word   bool_var
       .word   outbuf
       .size   test, .-test
       .ident  "GCC: (GNU) 4.4.0"

, while GCC 4.2.1 generates the following code:

       .code   16
       .file   "outcnt.c"
       .text
       .align  2
       .global test
       .code 16
       .thumb_func
       .type   test, %function
test:
       push    {lr}
       ldr     r2, .L6
       mov     r3, #0
       str     r3, [r2]
       ldr     r3, .L6+4
       ldr     r3, [r3]
       cmp     r3, #0
       beq     .L2
       mov     r2, #2
       b       .L4
.L2:
       mov     r2, #0
.L4:
       ldr     r3, .L6+8
       @ sp needed for prologue
       strb    r2, [r3]
       pop     {pc}
.L7:
       .align  2
.L6:
       .word   outcnt
       .word   bool_var
       .word   outbuf
       .size   test, .-test
       .ident  "GCC: (GNU) 4.2.1"

The code snippet has a lot of dead code that is not completely eliminated by
gcc 4.4.0 (but correctly eliminated by gcc 4.2.1).
Because outcnt == 0, all lines 'if (outcnt == 1)' can be eliminated. Because
outbuf and outcnt are global external symbols of different types, they can not
be aliased, so the last statement can be also eliminated.
gcc 4.2.1 output is 40 bytes, gcc 4.4.0 output is 52 bytes. It also inserts 'bl
func'. 

This code snippet was extracted from gzip benchmark, but got changed quite a
bit.


-- 
           Summary: Regression on dead-code-elimination: GCC 4.2.1 generates
                    better code than 4.4.0
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sliao at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


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


^ permalink raw reply	[flat|nested] 26+ messages in thread
[parent not found: <bug-42494-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2012-03-13 16:01 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-25  5:42 [Bug c/42494] New: Regression on dead-code-elimination: GCC 4.2.1 generates better code than 4.4.0 sliao at google dot com
2009-12-29 10:35 ` [Bug c/42494] [4.4 only] " ramana at gcc dot gnu dot org
2009-12-29 11:31 ` [Bug c/42494] [4.4 Regression] Missed " steven at gcc dot gnu dot org
2009-12-29 12:45 ` [Bug tree-optimization/42494] " ramana at gcc dot gnu dot org
2009-12-30 23:21 ` [Bug tree-optimization/42494] [4.4 Regression] Missed dead-code-elimination rguenth at gcc dot gnu dot org
2009-12-30 23:34 ` rguenth at gcc dot gnu dot org
2009-12-31 15:36 ` rguenth at gcc dot gnu dot org
2010-01-07  9:19 ` sliao at google dot com
2010-01-07  9:49 ` steven at gcc dot gnu dot org
2010-01-07 21:30 ` steven at gcc dot gnu dot org
2010-01-07 21:36 ` steven at gcc dot gnu dot org
2010-01-07 22:08 ` steven at gcc dot gnu dot org
2010-01-07 22:08 ` steven at gcc dot gnu dot org
2010-01-21 13:19 ` jakub at gcc dot gnu dot org
2010-02-08 16:45 ` steven at gcc dot gnu dot org
2010-04-30  8:58 ` jakub at gcc dot gnu dot org
     [not found] <bug-42494-4@http.gcc.gnu.org/bugzilla/>
2010-10-01 11:59 ` jakub at gcc dot gnu.org
2011-04-16 11:02 ` jakub at gcc dot gnu.org
2011-04-16 11:29 ` jingyu at google dot com
2011-05-13 19:46 ` lacombar at gmail dot com
2011-05-13 20:19 ` jingyu at google dot com
2011-05-13 20:51 ` lacombar at gmail dot com
2011-05-18 11:21 ` rguenth at gcc dot gnu.org
2011-05-18 11:46 ` jingyu at google dot com
2011-05-18 15:29 ` lacombar at gmail dot com
2012-03-13 16:01 ` 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).