https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128310
Bug ID: 128310
Summary: [14/15/16/17 Regression] wrong code at -O2 with
_mm_crc32_u16 and _mm_crc32_u32 on the same constant
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
#include <immintrin.h>
#include <stdint.h>
__attribute__((noipa)) int a(uint32_t c)
{
uint32_t x = _mm_crc32_u16(c, 0x80);
uint32_t y = _mm_crc32_u32(c, 0x80);
return x == y;
}
int main(void)
{
if (a(7))
__builtin_abort();
return 0;
}
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 134
Program terminated with signal SIGABRT (6)
The 16-bit and the 32-bit CRC32 of the same value differ, so a(7) must return
0. Instead a returns 1 and main aborts. This happens at -O2 with -msse4.2 or
-mcrc32 (-O1 is fine), when both calls get the same constant: the two crc32
results are treated as equal.
Compiler Explorer:
https://godbolt.org/z/8E5jxfe7Y