intel/brw: Fix undefined left shift of negative value in update_uip_jip

When -fsanitize=shift is used, many instances of the following are
produced:

src/intel/compiler/brw_eu_compact.c:2244:50: runtime error: left shift of negative value -306

v2: Add comment and assertion to explain why the shift is
safe. Suggested by Caio.

Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30333>
This commit is contained in:
Ian Romanick
2024-07-22 18:52:09 -07:00
parent 228e049db6
commit abb7c012ff
+8 -2
View File
@@ -2237,11 +2237,17 @@ update_uip_jip(const struct brw_isa_info *isa, brw_inst *insn,
/* JIP and UIP are in units of bytes on Gfx8+. */
int shift = 3;
/* Even though the values are signed, we don't need the rounding behavior
* of integer division. The shifts are safe.
*/
assert(brw_inst_jip(devinfo, insn) % 8 == 0 &&
brw_inst_uip(devinfo, insn) % 8 == 0);
int32_t jip_compacted = brw_inst_jip(devinfo, insn) >> shift;
jip_compacted -= compacted_between(this_old_ip,
this_old_ip + (jip_compacted / 2),
compacted_counts);
brw_inst_set_jip(devinfo, insn, jip_compacted << shift);
brw_inst_set_jip(devinfo, insn, (uint32_t)jip_compacted << shift);
if (brw_inst_opcode(isa, insn) == BRW_OPCODE_ENDIF ||
brw_inst_opcode(isa, insn) == BRW_OPCODE_WHILE)
@@ -2251,7 +2257,7 @@ update_uip_jip(const struct brw_isa_info *isa, brw_inst *insn,
uip_compacted -= compacted_between(this_old_ip,
this_old_ip + (uip_compacted / 2),
compacted_counts);
brw_inst_set_uip(devinfo, insn, uip_compacted << shift);
brw_inst_set_uip(devinfo, insn, (uint32_t)uip_compacted << shift);
}
static void