https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376
Bug ID: 85376
Summary: [8 Regression] wrong code with -Og -fno-dce -fgcse
-fno-tree-ccp -fno-tree-copy-prop
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zsojka at seznam dot cz
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Created attachment 43918
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43918&action=edit
reduced testcase
Output:
$ x86_64-pc-linux-gnu-gcc -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop
testcase.c -Wno-psabi
$ ./a.out
Aborted
At the assembly level:
...
# testcase.c:16: q[7] >>= __builtin_add_overflow (0xfffffff0, __builtin_ffs
(n), &s[5]);
mov eax, 0 # tmp201,
bsf edx, eax # _28, tmp201
mov ecx, -16 # tmp204,
add eax, ecx # tmp203, tmp204
mov DWORD PTR [rsp+404], ecx # s, tmp204
# testcase.c:17: t = __builtin_ffs (g[7]);
bsf eax, DWORD PTR g[rip+28] # _38, g
lea ecx, [rcx+15] # tmp206,
cmove eax, ecx # tmp206,, _38
add eax, 1 # _38,
# testcase.c:18: e *= __builtin_sub_overflow (o, t, &f);
mov ecx, 0 # _41,
sub dl, al # tmp208, _38
jb .L7 #,
...
"sub dl, al" is using edx set in "bsf edx, eax", which is not related (and even
undefined because eax == 0).
Use of ecx is correct, even though it does not look so on the first sight ("lea
ecx, [rcx+15]" just sets ecx=-1 with affecting the flags)
$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-259340-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--disable-bootstrap --with-cloog --with-ppl --with-isl
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-259340-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
gcc version 8.0.1 20180412 (experimental) (GCC)