From 54a4e75223e57e22a21c46d3b7721b5943f5d044 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 22 Apr 2021 16:02:36 +0200 Subject: [PATCH] pan/midg: Make sure the constant offset is in range in mir_match_iadd() The offset field is an 18-bit signed integer, if the offset is bigger than that we can get rid of the intermediate iadd. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig Part-of: --- src/panfrost/midgard/midgard_address.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/panfrost/midgard/midgard_address.c b/src/panfrost/midgard/midgard_address.c index 54e942a3457..c55e0fbe2c5 100644 --- a/src/panfrost/midgard/midgard_address.c +++ b/src/panfrost/midgard/midgard_address.c @@ -85,6 +85,9 @@ mir_match_constant(struct mir_address *address) /* Matches an iadd when there is a free slot or constant */ +/* The offset field is a 18-bit signed integer */ +#define MAX_POSITIVE_OFFSET ((1 << 17) - 1) + static void mir_match_iadd(struct mir_address *address, bool first_free) { @@ -101,13 +104,17 @@ mir_match_iadd(struct mir_address *address, bool first_free) nir_ssa_scalar op1 = nir_ssa_scalar_chase_alu_src(address->B, 0); nir_ssa_scalar op2 = nir_ssa_scalar_chase_alu_src(address->B, 1); - if (nir_ssa_scalar_is_const(op1)) { + if (nir_ssa_scalar_is_const(op1) && + nir_ssa_scalar_as_uint(op1) <= MAX_POSITIVE_OFFSET) { address->bias += nir_ssa_scalar_as_uint(op1); address->B = op2; - } else if (nir_ssa_scalar_is_const(op2)) { + } else if (nir_ssa_scalar_is_const(op2) && + nir_ssa_scalar_as_uint(op2) <= MAX_POSITIVE_OFFSET) { address->bias += nir_ssa_scalar_as_uint(op2); address->B = op1; - } else if (first_free && !address->A.def) { + } else if (!nir_ssa_scalar_is_const(op1) && + !nir_ssa_scalar_is_const(op2) && + first_free && !address->A.def) { address->A = op1; address->B = op2; }