https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122793
Bug ID: 122793
Summary: [15/16 regression] ffmpeg miscompiled with -O2
-march=x86-64-v2
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: sjames at gcc dot gnu.org
Target Milestone: ---
This originally comes from ffmpeg's testsuite, not sure if overreduced as it
fails w/ 15, not just trunk like the original:
```
#include <stdint.h>
#include <stdlib.h>
typedef uint8_t pixel;
static __attribute__((always_inline)) inline const unsigned
av_clip_uintp2_c(int a, int p) {
if (a & ~((1U << p) - 1))
return (~a) >> 31 & ((1U << p) - 1);
else
return a;
}
#define CLIP(a) av_clip_uintp2_c(a, 10)
#define op_put(a, b) a = CLIP(((b) + 16) >> 5)
static void(avg_h264_qpel8_h_lowpass)(uint8_t *_dst,
const uint8_t *restrict _src,
int dstStride, int srcStride) {
const int h = 8;
int i;
pixel *dst = (pixel *)_dst;
const pixel *restrict src = (const pixel *)_src;
dstStride >>= sizeof(pixel) - 1;
srcStride >>= sizeof(pixel) - 1;
for (i = 0; i < h; i++) {
op_put(dst[0], (src[0] + src[1]) * 20 - (src[-1] + src[2]) * 5 +
(src[-2] + src[3]));
op_put(dst[1],
(src[1] + src[2]) * 20 - (src[0] + src[3]) * 5 + (src[-1] +
src[4]));
op_put(dst[2],
(src[2] + src[3]) * 20 - (src[1] + src[4]) * 5 + (src[0] + src[5]));
op_put(dst[3],
(src[3] + src[4]) * 20 - (src[2] + src[5]) * 5 + (src[1] + src[6]));
op_put(dst[4],
(src[4] + src[5]) * 20 - (src[3] + src[6]) * 5 + (src[2] + src[7]));
op_put(dst[5],
(src[5] + src[6]) * 20 - (src[4] + src[7]) * 5 + (src[3] + src[8]));
op_put(dst[6],
(src[6] + src[7]) * 20 - (src[5] + src[8]) * 5 + (src[4] + src[9]));
op_put(dst[7],
(src[7] + src[8]) * 20 - (src[6] + src[9]) * 5 + (src[5] +
src[10]));
dst += dstStride;
src += srcStride;
}
}
uint8_t src[128] = {
0x0, 0x0, 0x83, 0x3, 0x2f, 0x2, 0x2c, 0x0, 0xa4, 0x2, 0x25, 0x2, 0x89,
0x0,
0xb8, 0x0, 0x79, 0x1, 0x4f, 0x1, 0xcb, 0x1, 0x1c, 0x0, 0xbd, 0x1, 0x54,
0x2,
0x4a, 0x0, 0x62, 0x3, 0xd7, 0x1, 0xd7, 0x3, 0x8a, 0x3, 0x70, 0x3, 0x46,
0x3,
0x2d, 0x1, 0xc8, 0x2, 0xb0, 0x0, 0x66, 0x1, 0xab, 0x3, 0x5c, 0x1, 0x9e};
int main() {
uint8_t *dst = calloc(128, sizeof(uint8_t));
avg_h264_qpel8_h_lowpass(dst + 2, src + 2, 16, 16);
if (dst[54] != 101)
__builtin_abort();
}
```
```
$ gcc f.c -o f -O2 -march=x86-64-v2
$ ./f
Aborted (core dumped) ./f
```
```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-16.0.9999/work/gcc-16.0.9999/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/16
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/16/python
--enable-libphobos --enable-objc-gc
--enable-languages=c,c++,d,objc,obj-c++,fortran,ada,cobol,algol68,m2,rust,jit
--enable-obsolete --enable-secureplt --disable-werror --with-system-zlib
--enable-nls --without-included-gettext --disable-libunwind-exceptions
--enable-checking=yes,extra,rtl --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo Hardened 16.0.9999 p, commit
14943e8bf0215db509405c494327ad39d11e02ff' --with-gcc-major-version-only
--enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-multilib --with-multilib-list=m32,mx32,m64 --disable-fixed-point
--with-abi=m64 --enable-targets=all --enable-offload-defaulted
--enable-offload-targets=nvptx-none --enable-libgomp --disable-libssp
--enable-libada --disable-cet --enable-systemtap --enable-valgrind-annotations
--disable-vtable-verify --disable-libvtv --with-zstd --with-isl
--disable-isl-version-check --enable-default-pie --enable-host-pie
--enable-host-bind-now --enable-default-ssp --disable-fixincludes
--with-gxx-libcxx-include-dir=/usr/include/c++/v1 --enable-host-shared
--enable-libgdiagnostics --enable-linker-build-id --enable-linker-build-id
--enable-linker-build-id --enable-linker-build-id
--with-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20251120 (experimental)
cb8c1f7c0743ef8281dbd6615f8e3a95eea35bc1 (Gentoo Hardened 16.0.9999 p, commit
14943e8bf0215db509405c494327ad39d11e02ff)
```