public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/19702] New: suboptimal multiple branch comparison code produced
@ 2005-01-30  1:53 yuri at tsoft dot com
  2005-01-30  2:03 ` [Bug middle-end/19702] " pinskia at gcc dot gnu dot org
  2005-01-31 14:28 ` kazu at cs dot umass dot edu
  0 siblings, 2 replies; 3+ messages in thread
From: yuri at tsoft dot com @ 2005-01-30  1:53 UTC (permalink / raw)
  To: gcc-bugs

When two comparisons immediately follow each other that compare same numbers but
branch twice based on 3 possible comparison outcomes actual comparison is
performed twice in asm code. One comparision suffices.

Also if second branches are strongly disadvantaged even pre-jxx mov for each
branch should be moved outside of the main body of the function.

Yuri (yuri at ONLYtsoftLOWER CASEcomMATTERS)


-- begin code --
int f(int k) {
  if (k < 300)
    return (10);
  if (k > 300)
    return (-10);
  return (0);
}

int main() { f(299); }
-- end code --

obtained assembly log:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   8b 55 08                mov    0x8(%ebp),%edx
   6:   81 fa 2b 01 00 00       cmp    $0x12b,%edx
   c:   b8 0a 00 00 00          mov    $0xa,%eax
  11:   7e 0f                   jle    22 <_Z1fi+0x22>
  13:   81 fa 2c 01 00 00       cmp    $0x12c,%edx
  19:   b8 f6 ff ff ff          mov    $0xfffffff6,%eax
  1e:   7f 02                   jg     22 <_Z1fi+0x22>
  20:   31 c0                   xor    %eax,%eax
  22:   c9                      leave
  23:   c3                      ret

expected assembly log:
  :     55                      push   %ebp
  :     89 e5                   mov    %esp,%ebp
  :     8b 55 08                mov    0x8(%ebp),%edx
  :     81 fa 2b 01 00 00       cmp    $0x12b,%edx
  :     b8 0a 00 00 00          mov    $0xa,%eax
  :     7e 0f                   jle    22 <_Z1fi+ret>
  :     b8 f6 ff ff ff          mov    $0xfffffff6,%eax
  :     7f 02                   je     22 <_Z1fi+ret>
  :     31 c0                   xor    %eax,%eax
ret:    c9                      leave
  :     c3                      ret

-- 
           Summary: suboptimal multiple branch comparison code produced
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yuri at tsoft dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug middle-end/19702] suboptimal multiple branch comparison code produced
  2005-01-30  1:53 [Bug rtl-optimization/19702] New: suboptimal multiple branch comparison code produced yuri at tsoft dot com
@ 2005-01-30  2:03 ` pinskia at gcc dot gnu dot org
  2005-01-31 14:28 ` kazu at cs dot umass dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-30  2:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-30 02:03 -------
Confirmed.
The problem is that fold changes "k < 300" to "k <= 299".

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|rtl-optimization            |middle-end
     Ever Confirmed|                            |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-30 02:03:14
               date|                            |


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


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

* [Bug middle-end/19702] suboptimal multiple branch comparison code produced
  2005-01-30  1:53 [Bug rtl-optimization/19702] New: suboptimal multiple branch comparison code produced yuri at tsoft dot com
  2005-01-30  2:03 ` [Bug middle-end/19702] " pinskia at gcc dot gnu dot org
@ 2005-01-31 14:28 ` kazu at cs dot umass dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-01-31 14:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2005-01-31 14:28 -------


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

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


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


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

end of thread, other threads:[~2005-01-31 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-30  1:53 [Bug rtl-optimization/19702] New: suboptimal multiple branch comparison code produced yuri at tsoft dot com
2005-01-30  2:03 ` [Bug middle-end/19702] " pinskia at gcc dot gnu dot org
2005-01-31 14:28 ` kazu at cs dot umass dot edu

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).