From ac4b93571cfba02bcbd589f2008f615ecf1813c4 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 24 Jan 2025 10:43:28 -0800 Subject: [PATCH] brw/copy: Fix handling of offset in extract_imm The offset is measured in bytes. Some of the code here acted as though it were measured in src.type units. Also modify the assertion to check that all extracted bits come from data in the immediate value. Fixes: 580e1c592d90 ("intel/brw: Introduce a new SSA-based copy propagation pass") Fixes: da395e6985a ("intel/brw: Fix extract_imm for subregion reads of 64-bit immediates") Yes, I missed this error *twice* in code review. Reviewed-by: Kenneth Graunke Part-of: --- src/intel/compiler/brw_opt_copy_propagation.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/intel/compiler/brw_opt_copy_propagation.cpp b/src/intel/compiler/brw_opt_copy_propagation.cpp index 7c3f3737026..4773d832681 100644 --- a/src/intel/compiler/brw_opt_copy_propagation.cpp +++ b/src/intel/compiler/brw_opt_copy_propagation.cpp @@ -1739,9 +1739,12 @@ extract_imm(brw_reg val, brw_reg_type type, unsigned offset) if (offset == 0 || bitsize == brw_type_size_bits(val.type)) return val; - assert(bitsize < brw_type_size_bits(val.type)); + /* The whole extracted value must come from bits that acutally exist in the + * original immediate value. + */ + assert((8 * offset) + bitsize <= brw_type_size_bits(val.type)); - val.u64 = (val.u64 >> (bitsize * offset)) & ((1ull << bitsize) - 1); + val.u64 = (val.u64 >> (8 * offset)) & ((1ull << bitsize) - 1); return val; }