public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
@ 2009-05-08 16:04 vvv at ru dot ru
2009-05-08 16:08 ` [Bug target/40072] " steven at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: vvv at ru dot ru @ 2009-05-08 16:04 UTC (permalink / raw)
To: gcc-bugs
Sometimes GCC generate code at end of function:
cmovge %eax,%edi
mov %edi,%eax
retq
but faster:
cmovl %edi,%eax
retq
Example:
# cat test.c
#define MX 0
#define LIM 7
char char_char(char m)
{if(m>LIM) return(MX); return(m);}
char char_int(int m)
{if(m>LIM) return(MX); return(m);}
char char_uint(unsigned int m)
{if(m>LIM) return(MX); return(m);}
char char_long(long m)
{if(m>LIM) return(MX); return(m);}
char char_ulong(unsigned long m)
{if(m>LIM) return(MX); return(m);}
int int_char(char m)
{if(m>LIM) return(MX); return(m);}
int int_int(int m)
{if(m>LIM) return(MX); return(m);} // Nonoptimal
int int_uint(unsigned int m)
{if(m>LIM) return(MX); return(m);}
int int_long(long m)
{if(m>LIM) return(MX); return(m);}
int int_ulong(unsigned long m)
{if(m>LIM) return(MX); return(m);}
unsigned int uint_char(char m)
{if(m>LIM) return(MX); return(m);}
unsigned int uint_int(int m)
{if(m>LIM) return(MX); return(m);}
unsigned int uint_uint(unsigned int m) //Nonoptimal
{if(m>LIM) return(MX); return(m);}
unsigned int uint_long(long m)
{if(m>LIM) return(MX); return(m);}
unsigned int uint_ulong(unsigned long m)
{if(m>LIM) return(MX); return(m);}
long long_char(char m)
{if(m>LIM) return(MX); return(m);}
long long_int(int m)
{if(m>LIM) return(MX); return(m);}
long long_uint(unsigned int m)
{if(m>LIM) return(MX); return(m);}
long long_long(long m) //Nonoptimal
{if(m>LIM) return(MX); return(m);}
long long_ulong(unsigned long m)
{if(m>LIM) return(MX); return(m);}
unsigned long ulong_char(char m)
{if(m>LIM) return(MX); return(m);}
unsigned long ulong_int(int m)
{if(m>LIM) return(MX); return(m);}
unsigned long ulong_uint(unsigned int m)
{if(m>LIM) return(MX); return(m);}
unsigned long ulong_long(long m)
{if(m>LIM) return(MX); return(m);}
unsigned long ulong_ulong(unsigned long m) //Nonoptimal
{if(m>LIM) return(MX); return(m);}
# gcc -o t test.c -O2 -c
# objdump -d t
t: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <char_char>:
0: 89 f8 mov %edi,%eax
2: 40 80 ff 08 cmp $0x8,%dil
6: ba 00 00 00 00 mov $0x0,%edx
b: 0f 4d c2 cmovge %edx,%eax <--- It's ok! Optimal
e: c3 retq
f: 90 nop
<skip...>
0000000000000060 <int_int>:
60: 83 ff 08 cmp $0x8,%edi
63: b8 00 00 00 00 mov $0x0,%eax
68: 0f 4d f8 cmovge %eax,%edi <--- Nonoptimal
6b: 89 f8 mov %edi,%eax <--- Nonoptimal
6d: c3 retq
6e: 66 90 xchg %ax,%ax
<skip...>
00000000000000c0 <uint_uint>:
c0: 83 ff 08 cmp $0x8,%edi
c3: b8 00 00 00 00 mov $0x0,%eax
c8: 0f 43 f8 cmovae %eax,%edi <--- Nonoptimal
cb: 89 f8 mov %edi,%eax <--- Nonoptimal
cd: c3 retq
ce: 66 90 xchg %ax,%ax
<skip...>
0000000000000120 <long_long>:
120: 48 83 ff 08 cmp $0x8,%rdi
124: b8 00 00 00 00 mov $0x0,%eax
129: 48 0f 4d f8 cmovge %rax,%rdi <--- Nonoptimal
12d: 48 89 f8 mov %rdi,%rax <--- Nonoptimal
130: c3 retq
<skip...>
0000000000000190 <ulong_ulong>:
190: 48 83 ff 08 cmp $0x8,%rdi
194: b8 00 00 00 00 mov $0x0,%eax
199: 48 0f 43 f8 cmovae %rax,%rdi <--- Nonoptimal
19d: 48 89 f8 mov %rdi,%rax <--- Nonoptimal
1a0: c3 retq
--
Summary: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax;
retq
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vvv at ru dot ru
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/40072] Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
@ 2009-05-08 16:08 ` steven at gcc dot gnu dot org
2009-05-08 20:38 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-05-08 16:08 UTC (permalink / raw)
To: gcc-bugs
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |steven at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-05-08 16:08:31
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/40072] Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
2009-05-08 16:08 ` [Bug target/40072] " steven at gcc dot gnu dot org
@ 2009-05-08 20:38 ` rguenth at gcc dot gnu dot org
2009-05-09 12:03 ` vvv at ru dot ru
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-08 20:38 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|minor |enhancement
GCC target triplet| |x86_64-*-*
Keywords| |missed-optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/40072] Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
2009-05-08 16:08 ` [Bug target/40072] " steven at gcc dot gnu dot org
2009-05-08 20:38 ` rguenth at gcc dot gnu dot org
@ 2009-05-09 12:03 ` vvv at ru dot ru
2009-05-09 21:38 ` ubizjak at gmail dot com
2009-05-10 16:09 ` vvv at ru dot ru
4 siblings, 0 replies; 6+ messages in thread
From: vvv at ru dot ru @ 2009-05-09 12:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from vvv at ru dot ru 2009-05-09 12:02 -------
There is no bug for current trunk. So bug fixed.
--
vvv at ru dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/40072] Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
` (2 preceding siblings ...)
2009-05-09 12:03 ` vvv at ru dot ru
@ 2009-05-09 21:38 ` ubizjak at gmail dot com
2009-05-10 16:09 ` vvv at ru dot ru
4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2009-05-09 21:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ubizjak at gmail dot com 2009-05-09 21:37 -------
(In reply to comment #1)
> There is no bug for current trunk. So bug fixed.
Not really, the move insn is moved to the beginning of the function:
0000000000000060 <int_int>:
60: 89 f8 mov %edi,%eax
62: 83 ff 08 cmp $0x8,%edi
65: ba 00 00 00 00 mov $0x0,%edx
6a: 0f 4d c2 cmovge %edx,%eax
6d: c3 retq
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/40072] Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
` (3 preceding siblings ...)
2009-05-09 21:38 ` ubizjak at gmail dot com
@ 2009-05-10 16:09 ` vvv at ru dot ru
4 siblings, 0 replies; 6+ messages in thread
From: vvv at ru dot ru @ 2009-05-10 16:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from vvv at ru dot ru 2009-05-10 16:09 -------
> Not really, the move insn is moved to the beginning of the function:
> 0000000000000060 <int_int>:
> 60: 89 f8 mov %edi,%eax
> 62: 83 ff 08 cmp $0x8,%edi
> 65: ba 00 00 00 00 mov $0x0,%edx
> 6a: 0f 4d c2 cmovge %edx,%eax
> 6d: c3 retq
You are right. Bug reopen.
--
vvv at ru dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40072
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-05-10 16:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-08 16:04 [Bug c/40072] New: Nonoptimal code - CMOVxx %eax,%edi; mov %edi,%eax; retq vvv at ru dot ru
2009-05-08 16:08 ` [Bug target/40072] " steven at gcc dot gnu dot org
2009-05-08 20:38 ` rguenth at gcc dot gnu dot org
2009-05-09 12:03 ` vvv at ru dot ru
2009-05-09 21:38 ` ubizjak at gmail dot com
2009-05-10 16:09 ` vvv at ru dot ru
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).