From c30116a2faf6e2d1829c77b0beac58d960e248c1 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 26 Aug 2019 12:48:14 -0700 Subject: [PATCH] pan/midgard: Fix invert fusing with r26 The invert wasn't applying (correctly) due to the issues addressed here. Signed-off-by: Alyssa Rosenzweig --- src/panfrost/midgard/midgard_opt_invert.c | 17 +++++++++++++++-- src/panfrost/midgard/mir.c | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/panfrost/midgard/midgard_opt_invert.c b/src/panfrost/midgard/midgard_opt_invert.c index da0cff88649..c3dc8142663 100644 --- a/src/panfrost/midgard/midgard_opt_invert.c +++ b/src/panfrost/midgard/midgard_opt_invert.c @@ -193,6 +193,9 @@ midgard_opt_fuse_dest_invert(compiler_context *ctx, midgard_block *block) static bool mir_strip_inverted(compiler_context *ctx, unsigned node) { + if (node >= SSA_FIXED_MINIMUM) + return false; + /* Strips and returns the invert off a node */ mir_foreach_instr_global(ctx, ins) { if (ins->compact_branch) continue; @@ -206,6 +209,12 @@ mir_strip_inverted(compiler_context *ctx, unsigned node) unreachable("Invalid node stripped"); } +static bool +is_ssa_or_constant(unsigned node) +{ + return !(node & IS_REG) || (node == SSA_FIXED_REGISTER(26)); +} + bool midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block) { @@ -217,8 +226,8 @@ midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block) if (!mir_is_bitwise(ins)) continue; if (ins->invert) continue; - if (ins->src[0] & IS_REG) continue; - if (ins->src[1] & IS_REG) continue; + if (!is_ssa_or_constant(ins->src[0])) continue; + if (!is_ssa_or_constant(ins->src[1])) continue; if (!mir_single_use(ctx, ins->src[0])) continue; if (!ins->has_inline_constant && !mir_single_use(ctx, ins->src[1])) continue; @@ -252,6 +261,10 @@ midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block) unsigned temp = ins->src[0]; ins->src[0] = ins->src[1]; ins->src[1] = temp; + + temp = ins->alu.src1; + ins->alu.src1 = ins->alu.src2; + ins->alu.src2 = temp; } ins->alu.op = mir_notright_op(ins->alu.op); diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c index 0bf4c1d6021..e7129672344 100644 --- a/src/panfrost/midgard/mir.c +++ b/src/panfrost/midgard/mir.c @@ -231,6 +231,10 @@ mir_use_count(compiler_context *ctx, unsigned value) bool mir_single_use(compiler_context *ctx, unsigned value) { + /* We can replicate constants in places so who cares */ + if (value == SSA_FIXED_REGISTER(REGISTER_CONSTANT)) + return true; + return mir_use_count(ctx, value) <= 1; } -- 2.30.2