The following test fails when I disable all optimizations but if-conversion:
#include <stdio.h>
long long func(long arg) {
long long val = 0;
if (arg < 0) {
val = 0xffffffff80000000ull;
}
return val;
}
int main() {
long long result = func(-1);
if (result != 0xffffffff80000000ull) {
printf("failed.\n");
return 1;
}
printf("passed.\n");
return 0;
}
The return value of func is 0x80000000ull where it should be
0xffffffff80000000ull. It works correctly when I don't do any optimization or
with more optimization (-O1, -O2, -O3).
The compile command line is the following:
gcc test.c -O1 -fno-defer-pop -fno-delayed-branch -fno-guess-branch-probability
-fno-cprop-registers -fno-loop-optimize -fno-if-conversion2 -fno-tree-ccp
-fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-ter
-fno-tree-lrs -fno-tree-sra -fno-tree-copyrename -fno-tree-fre -fno-tree-ch
-fno-unit-at-a-time -fno-merge-constants -fno-omit-frame-pointer -o test
there are no compiler warnings, even with -Wall
I use gcc 4.3.4, configure options:
../gcc-4.3.4/configure --disable-shared --disable-nls --enable-languages=c++
--with-gnu-as --with-gnu-ld --enable-__cxa_atexit
--
Summary: Wrong optimization with if-conversion
Product: gcc
Version: 4.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thomas at coware dot com
GCC build triplet: i686
GCC host triplet: i686
GCC target triplet: i686
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987