From 5b8917bb9110e631c44f60e32bf6efa70d12adf8 Mon Sep 17 00:00:00 2001 From: Mark Collins Date: Mon, 28 Nov 2022 08:35:32 +0000 Subject: [PATCH] ir3: Propagate `coord_offset` result from `alu` src insts `coord_offset` is called on the source of `alu` instructions and it returns -1 for failures, this not explicitly checked for and as a result the fetch can incorrectly be upgraded to a prefetch when it isn't appropriate to do so. Signed-off-by: Mark Collins Part-of: --- src/freedreno/ir3/ir3_nir_lower_tex_prefetch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/freedreno/ir3/ir3_nir_lower_tex_prefetch.c b/src/freedreno/ir3/ir3_nir_lower_tex_prefetch.c index ec987b79d2f..45e65365864 100644 --- a/src/freedreno/ir3/ir3_nir_lower_tex_prefetch.c +++ b/src/freedreno/ir3/ir3_nir_lower_tex_prefetch.c @@ -48,16 +48,21 @@ coord_offset(nir_ssa_def *ssa) if (!alu->src[0].src.is_ssa) return -1; - int base_offset = - coord_offset(alu->src[0].src.ssa) + alu->src[0].swizzle[0]; + int base_src_offset = coord_offset(alu->src[0].src.ssa); + if (base_src_offset < 0) + return -1; + + int base_offset = base_src_offset + alu->src[0].swizzle[0]; /* NOTE it might be possible to support more than 2D? */ for (int i = 1; i < 2; i++) { if (!alu->src[i].src.is_ssa) return -1; - int nth_offset = - coord_offset(alu->src[i].src.ssa) + alu->src[i].swizzle[0]; + int nth_src_offset = coord_offset(alu->src[i].src.ssa); + if (nth_src_offset < 0) + return -1; + int nth_offset = nth_src_offset + alu->src[i].swizzle[0]; if (nth_offset != (base_offset + i)) return -1;