From 05d0fa894e07e1ebff36fa37148461b9c5b46423 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Mon, 14 Oct 2024 17:00:03 +0100 Subject: [PATCH] aco: allow applying sign-extended sel to p_extract more often In the case of v1=p_extract(v1=p_extract(src, 0, 16, 1), 0, 32, 0). When we apply extracts with sub-dword definitions, this will also include v2b=p_extract(v2b=p_extract(src, 0, 8, 1), 0, 16, 0). No fossil-db changes. Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/amd/compiler/aco_optimizer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index ff03ce6ce4e..d49e045c9b1 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -1068,7 +1068,9 @@ can_apply_extract(opt_ctx& ctx, aco_ptr& instr, unsigned idx, ssa_i return false; /* don't remove the sign-extension when increasing the size further */ - if (instrSel.size() > sel.size() && !instrSel.sign_extend() && sel.sign_extend()) + if (instrSel.size() > sel.size() && sel.sign_extend() && + !(instrSel.sign_extend() || (instrSel.size() == instr->operands[idx].bytes() && + instrSel.size() == instr->definitions[0].bytes()))) return false; return true; @@ -1149,7 +1151,7 @@ apply_extract(opt_ctx& ctx, aco_ptr& instr, unsigned idx, ssa_info& unsigned size = std::min(sel.size(), instrSel.size()); unsigned offset = sel.offset() + instrSel.offset(); unsigned sign_extend = - instrSel.sign_extend() && (sel.sign_extend() || instrSel.size() <= sel.size()); + instrSel.size() <= sel.size() ? instrSel.sign_extend() : sel.sign_extend(); instr->operands[1] = Operand::c32(offset / size); instr->operands[2] = Operand::c32(size * 8u);