https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124435
Bug ID: 124435
Summary: [16 Regression] wrong code with signed short shift
right at -O1 and above
Product: gcc
Version: 16.0
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: mips64el-unknown-linux-gnuabi64
Created attachment 63870
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63870&action=edit
reduced testcase
Output:
$ mips64el-unknown-linux-gnuabi64-gcc -O1 testcase.c -static
$ qemu-mips64el -- ./a.out
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted qemu-mips64el -- ./a.out
The difference between OK (gcc-15) to BAD ASM is:
@@ -29,9 +29,8 @@
daddiu $2,$2,255
and $2,$4,$2
or $2,$2,$3
- dsll $2,$2,48
jr $31
- dsra $2,$2,58
+ dsra $2,$2,10
.set macro
.set reorder
eg. gcc-16 omits the shift left first, so it seems the "garbage" is shifted in
during the right shift.
$ mips64el-unknown-linux-gnuabi64-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-mips64el/bin/mips64el-unknown-linux-gnuabi64-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-20260309124537-r16-7957-ge1eb2472c965a1-checking-yes-rtl-df-extra-mips64el/bin/../libexec/gcc/mips64el-unknown-linux-gnuabi64/16.0.1/lto-wrapper
Target: mips64el-unknown-linux-gnuabi64
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--enable-libsanitizer --with-sysroot=/usr/mips64el-unknown-linux-gnuabi64
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=mips64el-unknown-linux-gnuabi64
--with-ld=/usr/bin/mips64el-unknown-linux-gnuabi64-ld
--with-as=/usr/bin/mips64el-unknown-linux-gnuabi64-as --disable-multilib
--with-abi=64 --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-20260309124537-r16-7957-ge1eb2472c965a1-checking-yes-rtl-df-extra-mips64el
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.1 20260309 (experimental) (GCC)