Workaround code generation bug in clang
authorJohn Naylor
Mon, 16 Jun 2025 02:27:15 +0000 (09:27 +0700)
committerJohn Naylor
Mon, 16 Jun 2025 02:27:15 +0000 (09:27 +0700)
At optimization level -O0, builds on recent clang fail to produce the
correct CRC32C with our AVX-512 implementation. For now, just disable
the runtime check for clang at -O0. When this is fixed upstream and we
know the extent of the breakage, we can adjust to be version-specific.

Reported-by: Soumyadeep Chakraborty
Reported-by: Andy Fan
Tested-by: Andy Fan
Discussion: https://postgr.es/m/CAE-ML%2B-OV6p9uvCFBcSQjZUEh__y0h-KjN%2BBseyGJHt7u8EP%2Bw%40mail.gmail.com
Discussion: https://postgr.es/m/87o6uqd3iv.fsf%40163.com

src/port/pg_crc32c_sse42_choose.c

index 74d2421ba2be99cd73883388469e3fad8e5e557b..802e47788c10c34f907880a9fe646ad6767b0199 100644 (file)
@@ -95,7 +95,9 @@ pg_comp_crc32c_choose(pg_crc32c crc, const void *data, size_t len)
            __cpuidex(exx, 7, 0);
 #endif
 
-#ifdef USE_AVX512_CRC32C_WITH_RUNTIME_CHECK
+#if defined(__clang__) && !defined(__OPTIMIZE__)
+           /* Some versions of clang are broken at -O0 */
+#elif defined(USE_AVX512_CRC32C_WITH_RUNTIME_CHECK)
            if (exx[2] & (1 << 10) &&   /* VPCLMULQDQ */
                exx[1] & (1 << 31)) /* AVX512-VL */
                pg_comp_crc32c = pg_comp_crc32c_avx512;