From 0674c9d30e9d1a627eda07041504bdb625f69d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 30 Dec 2025 14:26:12 +0100 Subject: [PATCH] aco/validate: Validate correct RegisterClasses after lowering to HW instructions Part-of: --- src/amd/compiler/aco_validate.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/amd/compiler/aco_validate.cpp b/src/amd/compiler/aco_validate.cpp index 02aba6c33bf..98ed39f9433 100644 --- a/src/amd/compiler/aco_validate.cpp +++ b/src/amd/compiler/aco_validate.cpp @@ -134,14 +134,35 @@ validate_ir(Program* program) for (Block& block : program->blocks) { for (aco_ptr& instr : block.instructions) { - if (program->progress < CompilationProgress::after_lower_to_hw) { - for (const Operand& op : instr->operands) + /* Check that register assignment and register class are consistent. */ + for (const Operand& op : instr->operands) { + if (program->progress < CompilationProgress::after_lower_to_hw) check(!op.isTemp() || op.regClass() == program->temp_rc[op.tempId()], "Operand RC not consistent.", instr.get()); - for (const Definition& def : instr->definitions) + if (program->progress >= CompilationProgress::after_ra) + check(op.isFixed(), "Operand without register assignment.", instr.get()); + + check(!op.hasRegClass() || op.isUndefined() || !op.isFixed() || + (op.physReg().reg() >= 256 + ? op.isOfType(RegType::vgpr) + : (op.isOfType(RegType::sgpr) && op.physReg().byte() == 0)), + "Operand RC and assignment not consistent.", instr.get()); + } + + for (const Definition& def : instr->definitions) { + if (program->progress < CompilationProgress::after_lower_to_hw) check(!def.isTemp() || def.regClass() == program->temp_rc[def.tempId()], "Definition RC not consistent.", instr.get()); + + if (program->progress >= CompilationProgress::after_ra) + check(def.isFixed(), "Definition without register assignment.", instr.get()); + + check(!def.isFixed() || + (def.physReg().reg() >= 256 + ? def.regClass().type() == RegType::vgpr + : (def.regClass().type() == RegType::sgpr && def.physReg().byte() == 0)), + "Definition RC and assignment not consistent.", instr.get()); } const aco_alu_opcode_info& opcode_info = instr_info.alu_opcode_infos[(int)instr->opcode];