public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44474]  New: GCC inserts redundant "test" instruction due to incorrect clobber
@ 2010-06-09  4:20 darkshikari at gmail dot com
  2010-06-09  9:31 ` [Bug target/44474] " rguenth at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: darkshikari at gmail dot com @ 2010-06-09  4:20 UTC (permalink / raw)
  To: gcc-bugs

Take the following test case:

int foo();

int test( int *b )
{
    (*b)--;
    if( *b == 0 )
        return foo();
    return 0;
}

On x86_64, with "-fomit-frame-pointer -O3 -c", gcc 4.6 compiles this to:

   0:   8b 07                   mov    eax, [rdi]
   2:   83 e8 01                sub    eax, 0x1
   5:   85 c0                   test   eax, eax
   7:   89 07                   mov    [rdi], eax
   9:   74 05                   je     10 <test+0x10>
   b:   31 c0                   xor    eax, eax
   d:   c3                      ret
 10:    e9 00 00 00 00          jmp    15 <test+0x15> //foo

As can be seen, gcc inserts a redundant "test" instruction.  This problem is
present in all versions of gcc I tested (3.4, 4.3.4, 4.4.1, and 4.6 SVN
r160330).

According to Alexander Strange on IRC:

<astrange> the problem is that subl $1, %eax does (clobber (reg:CC 17 flags))
instead of (set (reg:CCZ 17 flags) (compare:CCZ ....
<astrange> which i don't think is fixable in a real way, but i didn't write it


-- 
           Summary: GCC inserts redundant "test" instruction due to
                    incorrect clobber
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: darkshikari at gmail dot com


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


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

* [Bug target/44474] GCC inserts redundant "test" instruction due to incorrect clobber
  2010-06-09  4:20 [Bug c/44474] New: GCC inserts redundant "test" instruction due to incorrect clobber darkshikari at gmail dot com
@ 2010-06-09  9:31 ` rguenth at gcc dot gnu dot org
  2010-07-01  3:43 ` astrange at ithinksw dot com
  2010-08-29  6:39 ` astrange at ithinksw dot com
  2 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-06-09  9:31 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|c                           |target
 GCC target triplet|                            |i?86-*-* x86_64-*-*


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


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

* [Bug target/44474] GCC inserts redundant "test" instruction due to incorrect clobber
  2010-06-09  4:20 [Bug c/44474] New: GCC inserts redundant "test" instruction due to incorrect clobber darkshikari at gmail dot com
  2010-06-09  9:31 ` [Bug target/44474] " rguenth at gcc dot gnu dot org
@ 2010-07-01  3:43 ` astrange at ithinksw dot com
  2010-08-29  6:39 ` astrange at ithinksw dot com
  2 siblings, 0 replies; 5+ messages in thread
From: astrange at ithinksw dot com @ 2010-07-01  3:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from astrange at ithinksw dot com  2010-07-01 03:43 -------
The problem is combine.

This:

int test2( int *b )
{
        int b_ = *b;
    b_--;
    if( b_ == 0 ) {
        *b = b_;
        return foo();
    }
    *b = b_;
    return 0;
}

works:
_test2:
LFB1:
        movl    (%rdi), %eax
        decl    %eax
        je      L7 <- uses decl
        movl    %eax, (%rdi)
        xorl    %eax, %eax
        ret
        .align 4,0x90
L7:
        movl    $0, (%rdi)
        xorl    %eax, %eax
        jmp     _foo

The original turns (*b)-- into load/dec/store/cmp - combine tries to combine
dec/store which fails, but doesn't try dec/cmp.


-- 


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


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

* [Bug target/44474] GCC inserts redundant "test" instruction due to incorrect clobber
  2010-06-09  4:20 [Bug c/44474] New: GCC inserts redundant "test" instruction due to incorrect clobber darkshikari at gmail dot com
  2010-06-09  9:31 ` [Bug target/44474] " rguenth at gcc dot gnu dot org
  2010-07-01  3:43 ` astrange at ithinksw dot com
@ 2010-08-29  6:39 ` astrange at ithinksw dot com
  2 siblings, 0 replies; 5+ messages in thread
From: astrange at ithinksw dot com @ 2010-08-29  6:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from astrange at ithinksw dot com  2010-08-29 06:39 -------
Still happens with the new combine work (not that I really expected it to
change).


-- 


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


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

* [Bug target/44474] GCC inserts redundant "test" instruction due to incorrect clobber
       [not found] <bug-44474-4@http.gcc.gnu.org/bugzilla/>
@ 2011-12-30 23:54 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-12-30 23:54 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-12-30
     Ever Confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-12-30 23:50:08 UTC ---
Confirmed.

Combine does:
Trying 7 -> 8:
Trying 9 -> 10:
But never 7 -> 9 which is needed for this to work.
This is for:
int foo();
int t;

int test( int b )
{
    (b)--;
    t = b;
    if( b == 0 )
        return foo();
    return 0;
}
--- CUT --
Where 7, 8, 9, and 10 are:
(insn 7 3 8 2 (parallel [
            (set (reg/v:SI 60 [ b ])
                (plus:SI (reg/v:SI 62 [ b ])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (reg:CC 17 flags))
        ]) t.c:6 253 {*addsi_1}
     (expr_list:REG_DEAD (reg/v:SI 62 [ b ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

(insn 8 7 9 2 (set (mem/c/i:SI (symbol_ref:DI ("t")  <var_decl 0x7fedc8e8c140
t>) [2 t+0 S4 A32])
        (reg/v:SI 60 [ b ])) t.c:7 64 {*movsi_internal}
     (nil))

(insn 9 8 10 2 (set (reg:CCZ 17 flags)
        (compare:CCZ (reg/v:SI 60 [ b ])
            (const_int 0 [0]))) t.c:8 2 {*cmpsi_ccno_1}
     (expr_list:REG_DEAD (reg/v:SI 60 [ b ])
        (nil)))

(jump_insn 10 9 11 2 (set (pc)
        (if_then_else (ne (reg:CCZ 17 flags)
                (const_int 0 [0]))
            (label_ref 16)
            (pc))) t.c:8 599 {*jcc_1}
     (expr_list:REG_DEAD (reg:CCZ 17 flags)
        (expr_list:REG_BR_PROB (const_int 6102 [0x17d6])
            (nil)))
 -> 16)


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

end of thread, other threads:[~2011-12-30 23:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09  4:20 [Bug c/44474] New: GCC inserts redundant "test" instruction due to incorrect clobber darkshikari at gmail dot com
2010-06-09  9:31 ` [Bug target/44474] " rguenth at gcc dot gnu dot org
2010-07-01  3:43 ` astrange at ithinksw dot com
2010-08-29  6:39 ` astrange at ithinksw dot com
     [not found] <bug-44474-4@http.gcc.gnu.org/bugzilla/>
2011-12-30 23:54 ` pinskia 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).