aco: Add some validation for PSEUDO_REDUCTION instructions.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7232>
diff --git a/src/amd/compiler/aco_validate.cpp b/src/amd/compiler/aco_validate.cpp
index 87a48d8..b1c4614 100644
--- a/src/amd/compiler/aco_validate.cpp
+++ b/src/amd/compiler/aco_validate.cpp
@@ -401,6 +401,19 @@
             }
             break;
          }
+         case Format::PSEUDO_REDUCTION: {
+            for (const Operand &op : instr->operands)
+               check(op.regClass().type() == RegType::vgpr, "All operands of PSEUDO_REDUCTION instructions must be in VGPRs.", instr.get());
+
+            unsigned cluster_size = static_cast<Pseudo_reduction_instruction *>(instr.get())->cluster_size;
+
+            if (instr->opcode == aco_opcode::p_reduce && cluster_size == program->wave_size)
+               check(instr->definitions[0].regClass().type() == RegType::sgpr, "The result of unclustered reductions must go into an SGPR.", instr.get());
+            else
+               check(instr->definitions[0].regClass().type() == RegType::vgpr, "The result of scans and clustered reductions must go into a VGPR.", instr.get());
+
+            break;
+         }
          case Format::SMEM: {
             if (instr->operands.size() >= 1)
                check((instr->operands[0].isFixed() && !instr->operands[0].isConstant()) ||