Commit Graph

1 Commits

Author SHA1 Message Date
9b4fef9bc7 Translator: avoid redundant 16-bit extract after lshr 16 on high-half reads (#1506)
AMD's Windows LLPC compiler (measured on RDNA2, drivers 22.40.84.06 in #1506
and 24.10.24 on Ryzen 5 7600 iGPU) drops the >> 16 when either
OpBitwiseAnd %uint (u >> 16) 0xFFFF or OpBitFieldSExtract %int (u >> 16) 0 16
follows two partial-half writes to u and feeds OpIAdd, OpIMul, or
OpShiftLeftLogical.

Add Gen.u16_half (OpShiftRightLogical %uint u 16 for high half, mask 0xFFFF
only for low half) and Gen.i16_half (OpShiftRightArithmetic %int u 16 for
high half, OpBitFieldSExtract 0 16 only for low half) and use them across all
16-bit half readers (v_*_b16/u16/i16, v_mad_{u,i}16, v_min3/max3/med3_{u,i}16,
v_cvt_f16_{u,i}16, v_pack_b32_f16, v_frexp_*_f16, v_ldexp_f16,
s_bitreplicate_b64_b32, and buffer_store_format_d16_*).

Fixes #1506.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
2026-11-22 20:14:52 +02:00