public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23869] New: Missed optimization with integer booleans when compiling for pentium and higher
@ 2005-09-13 19:45 guillaume dot melquiond at ens-lyon dot fr
2005-09-13 19:52 ` [Bug middle-end/23869] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2005-09-13 19:45 UTC (permalink / raw)
To: gcc-bugs
On x86 architectures, when the target is -march=pentium or higher, the compiler
seems to replace (x || y) by ((x | y) != 0) too soon for optimizations to apply,
when x and y are integers.
Testcase (compiled with "gcc -O3 -march=something"):
typedef int T;
void g(T);
void f(T x, T y) {
if (x || y) return;
g(!x);
}
When the target is -march=i386, GCC is doing a great job and it is able to
replace !x by 1 when optimizing:
if (x || y) return;
g(1);
However, when the target is -march=pentium, the generated code is equivalent to:
if ((x | y) != 0) return; /* this is a bit better than previously */
g(x != 0); /* this is a lot worse */
If int is replaced by _Bool in the typedef, then the code is correctly
optimized: !x is replaced by 1 whatever the target. So the misoptimization is
triggered only when boolean values are passed through integers (quite a common
situation in C) and when some specific x86 architectures are targeted.
$ gcc-snapshot -v
Using built-in specs.
Target: i686-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,obj-c++,treelang
--prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --disable-nls
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/gcc-snapshot/jre --enable-mpfr
--disable-werror i686-linux-gnu
Thread model: posix
gcc version 4.1.0 20050904 (experimental)
--
Summary: Missed optimization with integer booleans when compiling
for pentium and higher
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: guillaume dot melquiond at ens-lyon dot fr
CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i686-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23869
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-09-13 19:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-13 19:45 [Bug c/23869] New: Missed optimization with integer booleans when compiling for pentium and higher guillaume dot melquiond at ens-lyon dot fr
2005-09-13 19:52 ` [Bug middle-end/23869] " pinskia at gcc dot gnu dot 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).