agx: Only use nest by 1 for loops w/o continue

Apple doesn't do this, but it should be equivalent and it makes it easier to see
that we can use while_icmp for break_if_icmp in loops that don't use continue
(which Apple does do). So, the effect of this commit is to use while_icmp for
most breaks, which saves an instruction.

   total instructions in shared programs: 1764199 -> 1764076 (<.01%)
   instructions in affected programs: 24149 -> 24026 (-0.51%)
   helped: 78
   HURT: 0
   Instructions are helped.

   total bytes in shared programs: 11609306 -> 11608322 (<.01%)
   bytes in affected programs: 164604 -> 163620 (-0.60%)
   helped: 78
   HURT: 0
   Bytes are helped.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25052>
This commit is contained in:
Alyssa Rosenzweig
2023-08-29 18:39:37 -04:00
committed by Marge Bot
parent 8f06252e9b
commit 139e56c0db

View File

@@ -1783,9 +1783,8 @@ agx_emit_jump(agx_builder *b, nir_jump_instr *instr)
if (instr->type == nir_jump_continue) {
nestings += 1;
agx_block_add_successor(ctx->current_block, ctx->continue_block);
ctx->loop_continues = true;
} else if (instr->type == nir_jump_break) {
nestings += 2;
nestings += ctx->loop_continues ? 2 : 1;
agx_block_add_successor(ctx->current_block, ctx->break_block);
}
@@ -1984,6 +1983,7 @@ emit_loop(agx_context *ctx, nir_loop *nloop)
ctx->total_nesting++;
bool old_continues = ctx->loop_continues;
ctx->loop_continues = loop_uses_continue(nloop);
agx_block *popped_break = ctx->break_block;
agx_block *popped_continue = ctx->continue_block;
@@ -1997,7 +1997,7 @@ emit_loop(agx_context *ctx, nir_loop *nloop)
*/
agx_builder _b = agx_init_builder(ctx, agx_after_block(ctx->current_block));
if (ctx->total_nesting > 1)
agx_push_exec(&_b, 2);
agx_push_exec(&_b, ctx->loop_continues ? 2 : 1);
/* Fallthrough to body */
agx_block_add_successor(ctx->current_block, ctx->continue_block);
@@ -2023,7 +2023,7 @@ emit_loop(agx_context *ctx, nir_loop *nloop)
agx_while_icmp(&_b, agx_zero(), agx_zero(), 2, AGX_ICOND_UEQ, false);
agx_jmp_exec_any(&_b, start_block);
agx_pop_exec(&_b, 2);
agx_pop_exec(&_b, ctx->loop_continues ? 2 : 1);
agx_block_add_successor(ctx->current_block, ctx->continue_block);
/* Pop off */