nir: fix left shift of negative value in ibfe constant folding

Fixes "left shift of negative value -128" with parallel_rdp/00f93a9497dfbb3b
and UBSan.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35255>
This commit is contained in:
Rhys Perry 2025-05-27 11:58:46 +01:00 committed by Marge Bot
parent 78aae4b1ba
commit 397920c16e

View file

@ -1108,15 +1108,15 @@ if (bits == 0) {
""")
opcode("ibfe", 0, tint32,
[0, 0, 0], [tint32, tuint32, tuint32], False, "", """
int base = src0;
uint32_t base = src0;
unsigned offset = src1 & 0x1F;
unsigned bits = src2 & 0x1F;
if (bits == 0) {
dst = 0;
} else if (offset + bits < 32) {
dst = (base << (32 - bits - offset)) >> (32 - bits);
dst = util_mask_sign_extend(base >> offset, bits);
} else {
dst = base >> offset;
dst = util_mask_sign_extend(base >> offset, 32 - offset);
}
""")