From 8f0d4074ad680b89ebf8b9513bc71acdbd2e1ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 23 Apr 2024 15:06:38 +0200 Subject: [PATCH] aco/ra: fix kill flags after renaming fixed Operands Suggested-by: Rhys Perry Cc: mesa-stable Part-of: (cherry picked from commit be1e68b4ee97ed714417c8917182a5326f5b379f) --- .pick_status.json | 2 +- src/amd/compiler/aco_register_allocation.cpp | 42 +++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index d4144081d44..6783c1dae64 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2034,7 +2034,7 @@ "description": "aco/ra: fix kill flags after renaming fixed Operands", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp index f4f43890a02..4596dddf253 100644 --- a/src/amd/compiler/aco_register_allocation.cpp +++ b/src/amd/compiler/aco_register_allocation.cpp @@ -842,7 +842,7 @@ update_renames(ra_ctx& ctx, RegisterFile& reg_file, assert(ctx.assignments.size() == ctx.program->peekAllocationId()); /* check if we moved an operand */ - bool first = true; + bool first[2] = {true, true}; bool fill = true; for (unsigned i = 0; i < instr->operands.size(); i++) { Operand& op = instr->operands[i]; @@ -850,25 +850,31 @@ update_renames(ra_ctx& ctx, RegisterFile& reg_file, continue; if (op.tempId() == copy.first.tempId()) { /* only rename precolored operands if the copy-location matches */ - if ((flags & rename_precolored_ops) && op.isFixed() && - op.physReg() != copy.second.physReg()) + bool omit_renaming = (flags & rename_precolored_ops) && op.isFixed() && + op.physReg() != copy.second.physReg(); + + /* Omit renaming in some cases for p_create_vector in order to avoid + * unnecessary shuffle code. */ + if (!(flags & rename_not_killed_ops) && !op.isKillBeforeDef()) { + omit_renaming = true; + for (std::pair& pc : parallelcopies) { + PhysReg def_reg = pc.second.physReg(); + omit_renaming &= def_reg > copy.first.physReg() + ? (copy.first.physReg() + copy.first.size() <= def_reg.reg()) + : (def_reg + pc.second.size() <= copy.first.physReg().reg()); + } + } + + /* Fix the kill flags */ + if (first[omit_renaming]) + op.setFirstKill(omit_renaming || op.isKill()); + else + op.setKill(omit_renaming || op.isKill()); + first[omit_renaming] = false; + + if (omit_renaming) continue; - bool omit_renaming = !(flags & rename_not_killed_ops) && !op.isKillBeforeDef(); - for (std::pair& pc : parallelcopies) { - PhysReg def_reg = pc.second.physReg(); - omit_renaming &= def_reg > copy.first.physReg() - ? (copy.first.physReg() + copy.first.size() <= def_reg.reg()) - : (def_reg + pc.second.size() <= copy.first.physReg().reg()); - } - if (omit_renaming) { - if (first) - op.setFirstKill(true); - else - op.setKill(true); - first = false; - continue; - } op.setTemp(copy.second.getTemp()); op.setFixed(copy.second.physReg());