From aed317b83f012dea78d5e67f3e6e27af3e4141b2 Mon Sep 17 00:00:00 2001
From: Raghuveer Devulapalli <raghuveer.devulapalli@intel.com>
Date: Mon, 16 Jun 2025 21:16:43 -0700
Subject: [PATCH v1] Fix incorrect checksum calculation when build with -O0 opt
 flag

bug: fix checksum errors caused by undefined AVX-512 bits

Problem:
- _mm512_castsi128_si512 leaves upper 384 bits in undefined state
- Results in checksum failures when building PostgreSQL with clang -O0

Solution:
- Use _mm512_zextsi128_si512 to explicitly zero-extend __m128i to __m512i
---
 src/port/pg_crc32c_sse42.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/port/pg_crc32c_sse42.c b/src/port/pg_crc32c_sse42.c
index 9af3474a6ca..1a717255355 100644
--- a/src/port/pg_crc32c_sse42.c
+++ b/src/port/pg_crc32c_sse42.c
@@ -123,7 +123,7 @@ pg_comp_crc32c_avx512(pg_crc32c crc, const void *data, size_t len)
 		__m512i		k;
 
 		k = _mm512_broadcast_i32x4(_mm_setr_epi32(0x740eef02, 0, 0x9e4addf8, 0));
-		x0 = _mm512_xor_si512(_mm512_castsi128_si512(_mm_cvtsi32_si128(crc0)), x0);
+		x0 = _mm512_xor_si512(_mm512_zextsi128_si512(_mm_cvtsi32_si128(crc0)), x0);
 		buf += 64;
 
 		/* Main loop. */
-- 
2.43.0

