[Bug tree-optimization/67690] New: wrong code with -O2 on x86_64/Linux
eriksnga at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Sep 23 02:22:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67690
Bug ID: 67690
Summary: wrong code with -O2 on x86_64/Linux
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: eriksnga at gmail dot com
Target Milestone: ---
Created attachment 36374
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36374&action=edit
prepocessed source code
gcc-5.2.0 produces wrong code on x86_64-suse-linux (Intel/AMD) at -O2 and
higher.
gcc-4.9.1 on same platforms does not reproduce the problem.
Adding any of
-fno-inline-small-functions
-fno-tree-pre
-fno-tree-tail-merge
-fno-tree-vrp
restores the correct behaviour at -O2.
########################################################################
$ gcc-5.2.0 -v
Using built-in specs.
COLLECT_GCC=/opt/sandbox/gcc/5.2.0/bin/gcc
COLLECT_LTO_WRAPPER=/opt/sandbox/gcc/5.2.0/lib/gcc/x86_64-suse-linux/5.2.0/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../../gcc-5.2.0/configure --enable-languages=c,c++,fortran
--enable-targets=x86_64-suse-linux,i686-suse-linux
--prefix=/opt/sandbox/gcc/5.2.0 --with-gnu-as
--with-as=/opt/sandbox/gcc/binutils-2.25.1/bin/as --with-gnu-ld
--with-ld=/opt/sandbox/gcc/binutils-2.25.1/bin/ld.gold
--with-gmp=/opt/sandbox/gcc/gmp-5.0.1 --with-mpfr=/opt/sandbox/gcc/mpfr-3.0.0
--with-mpc=/opt/sandbox/gcc/mpc-0.8.2 --enable-threads=posix --enable-shared
--enable-__cxa_atexit --enable-libstdcxx-allocator=pool x86_64-suse-linux
Thread model: posix
gcc version 5.2.0 (GCC)
$
$
$ gcc-5.2.0 -pedantic-errors -Werror -Wall -Wextra -O2 testcase.c && ./a.out
Aborted
$
########################################################################
$ echo ; cat testcase.c ; echo
const int c1 = 1; /* >= 0 */
const int c2 = 2;
int check(int i)
{
int j;
if (i >= 0)
j = c2 - i;
else
j = c2 - i;
return c2 - c1 + 1 > j; /* c2 - c1 + 1 > c2 - c1 for i == c1 */
}
int invoke(int* pi) __attribute__ ((noinline,noclone));
int invoke(int* pi) { return check(*pi); }
int main()
{
int i = c1;
int ret = invoke(&i);
if (!ret) __builtin_abort();
return 0;
}
$
More information about the Gcc-bugs
mailing list