From 4791dc912504d011bc602bb80477d900ac71336f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 13 Apr 2022 18:34:50 -0400 Subject: [PATCH] agx: Make DCE dumber The current DCE pass hits issue around phi nodes. These need to be solved properly eventually, but for now workaround them by doing something obviously correct (but suboptimal compile time). Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_dce.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/asahi/compiler/agx_dce.c b/src/asahi/compiler/agx_dce.c index 9e2b8f1a3de..25c53252847 100644 --- a/src/asahi/compiler/agx_dce.c +++ b/src/asahi/compiler/agx_dce.c @@ -28,10 +28,22 @@ void agx_dce(agx_context *ctx) { - BITSET_WORD *seen = calloc(BITSET_WORDS(ctx->alloc), sizeof(BITSET_WORD)); + bool progress; + do { + progress = false; + + BITSET_WORD *seen = calloc(BITSET_WORDS(ctx->alloc), sizeof(BITSET_WORD)); + + agx_foreach_instr_global(ctx, I) { + agx_foreach_src(I, s) { + if (I->src[s].type == AGX_INDEX_NORMAL) + BITSET_SET(seen, I->src[s].value); + } + } + + agx_foreach_instr_global_safe_rev(ctx, I) { + if (!agx_opcodes_info[I->op].can_eliminate) continue; - agx_foreach_instr_global_safe_rev(ctx, I) { - if (agx_opcodes_info[I->op].can_eliminate) { bool needed = false; agx_foreach_dest(I, d) { @@ -43,15 +55,10 @@ agx_dce(agx_context *ctx) if (!needed) { agx_remove_instruction(I); - continue; + progress = true; } } - agx_foreach_src(I, s) { - if (I->src[s].type == AGX_INDEX_NORMAL) - BITSET_SET(seen, I->src[s].value); - } - } - - free(seen); + free(seen); + } while (progress); }