From 38447b3f634c0966e668cde13400b3a71a431f68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Wed, 3 May 2023 18:58:36 +0200 Subject: [PATCH] aco: Disallow constant propagation on SOPP and fixed operands. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Cc: mesa-stable Signed-off-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_optimizer.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/amd/compiler/aco_optimizer.cpp b/src/amd/compiler/aco_optimizer.cpp index 4c4cb5f..fff5bce 100644 --- a/src/amd/compiler/aco_optimizer.cpp +++ b/src/amd/compiler/aco_optimizer.cpp @@ -640,9 +640,20 @@ is_operand_vgpr(Operand op) /* only covers special cases */ bool -alu_can_accept_constant(aco_opcode opcode, unsigned operand) +alu_can_accept_constant(const aco_ptr& instr, unsigned operand) { - switch (opcode) { + /* Fixed operands can't accept constants because we need them + * to be in their fixed register. + */ + assert(instr->operands.size() > operand); + if (instr->operands[operand].isFixed()) + return false; + + /* SOPP instructions can't use constants. */ + if (instr->isSOPP()) + return false; + + switch (instr->opcode) { case aco_opcode::v_mac_f32: case aco_opcode::v_writelane_b32: case aco_opcode::v_writelane_b32_e64: @@ -1344,7 +1355,7 @@ label_instruction(opt_ctx& ctx, aco_ptr& instr) if (instr->isSALU() || instr->isPseudo()) { unsigned bits = get_operand_size(instr, i); if ((info.is_constant(bits) || (info.is_literal(bits) && instr->isPseudo())) && - !instr->operands[i].isFixed() && alu_can_accept_constant(instr->opcode, i)) { + alu_can_accept_constant(instr, i)) { instr->operands[i] = get_constant_op(ctx, info, bits); continue; } @@ -1407,7 +1418,7 @@ label_instruction(opt_ctx& ctx, aco_ptr& instr) continue; } - if (info.is_constant(bits) && alu_can_accept_constant(instr->opcode, i) && + if (info.is_constant(bits) && alu_can_accept_constant(instr, i) && (!instr->isSDWA() || ctx.program->gfx_level >= GFX9)) { Operand op = get_constant_op(ctx, info, bits); perfwarn(ctx.program, instr->opcode == aco_opcode::v_cndmask_b32 && i == 2, @@ -4874,7 +4885,7 @@ select_instruction(opt_ctx& ctx, aco_ptr& instr) continue; } - if (!alu_can_accept_constant(instr->opcode, i)) + if (!alu_can_accept_constant(instr, i)) continue; if (ctx.uses[op.tempId()] < literal_uses) { -- 2.7.4