https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115115
Bug ID: 115115 Summary: [12/13/14/15 Regression] highway-1.0.7 wrong _mm_cvttps_epi32() constant fold Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at gcc dot gnu.org Target Milestone: --- Initially I observed the testsuite failure on highway-1.0.7 library as on r15-523-g1a05332bbac98a. I reduced it down to the following: ```c // $ cat bug.c #include <emmintrin.h> #include <stdio.h> #include <stdint.h> #include <string.h> __attribute__((noipa)) static void dump_m128i(const char * prefix, const __m128i * v) { uint32_t p[4]; memcpy(p, v, 16); fprintf(stderr, "%s:", prefix); for (size_t i = 0; i < 4; ++i) { fprintf(stderr, " %#08x", p[i]); } fprintf(stderr, "\n"); } __attribute__((noipa)) static void assert_m128i(const __m128i * v) { uint32_t p[4]; memcpy(p, v, 16); uint32_t q[4] = { 0x80000000, 0x80000000, 0x80000000, 0x80000000, }; if (memcmp(p, q, 16) != 0) __builtin_abort(); } __attribute__((noipa)) static void TestAllF2IPromoteTo() { const __m128i iv = _mm_set_epi32(0x4f000000, 0x4f000000, 0x4f000000, 0x4f000000); const __m128 fv = _mm_castsi128_ps(iv); const __m128i riv = _mm_cvttps_epi32(fv); dump_m128i("riv", &riv); assert_m128i(&riv); } int main() { TestAllF2IPromoteTo(); } ``` Triggering: $ gcc-15 bug.c -o a -O0 && ./a riv: 0x80000000 0x80000000 0x80000000 0x80000000 # ok? $ gcc-15 bug.c -o a -O1 && ./a riv: 0x7fffffff 0x7fffffff 0x7fffffff 0x7fffffff Aborted (core dumped) # bad? I think highway expect the former. At least gcc-8/9/10/11 pass the test. gcc-12/13/14/15 all fail it. $ gcc -v Using built-in specs. COLLECT_GCC=/<<NIX>>/gcc-15.0.0/bin/gcc COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-15.0.0/libexec/gcc/x86_64-unknown-linux-gnu/15.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../source/configure --prefix=/<<NIX>>/gcc-15.0.0 --with-gmp-include=/<<NIX>>/gmp-6.3.0-dev/include --with-gmp-lib=/<<NIX>>/gmp-6.3.0/lib --with-mpfr-include=/<<NIX>>/mpfr-4.2.1-dev/include --with-mpfr-lib=/<<NIX>>/mpfr-4.2.1/lib --with-mpc=/<<NIX>>/libmpc-1.3.1 --with-native-system-header-dir=/<<NIX>>/glibc-2.39-52-dev/include --with-build-sysroot=/ --with-gxx-include-dir=/<<NIX>>/gcc-15.0.0/include/c++/15.0.0/ --program-prefix= --enable-lto --disable-libstdcxx-pch --without-included-gettext --with-system-zlib --enable-checking=release --enable-static --enable-languages=c,c++ --disable-multilib --enable-plugin --disable-libcc1 --with-isl=/<<NIX>>/isl-0.20 --disable-bootstrap --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=x86_64-unknown-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib gcc version 15.0.0 99999999 (experimental) (GCC)