aco: lower subdword phis with SGPR operands
authorDaniel Schürmann <daniel@schuermann.dev>
Tue, 7 Apr 2020 11:16:57 +0000 (12:16 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 10 Apr 2020 07:19:27 +0000 (07:19 +0000)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4492>

src/amd/compiler/aco_lower_bool_phis.cpp

index e5e27d709718c32b8d801cbddfeac0e6a99158ba..1613e4be94a052d5d0839692d975b255daf41a8e 100644 (file)
@@ -189,6 +189,30 @@ void lower_divergent_bool_phi(Program *program, Block *block, aco_ptr<Instructio
    return;
 }
 
+void lower_subdword_phis(Program *program, Block *block, aco_ptr<Instruction>& phi)
+{
+   Builder bld(program);
+   for (unsigned i = 0; i < phi->operands.size(); i++) {
+      if (phi->operands[i].isUndefined())
+         continue;
+      if (phi->operands[i].regClass() == phi->definitions[0].regClass())
+         continue;
+
+      assert(phi->operands[i].isTemp());
+      Block *pred = &program->blocks[block->logical_preds[i]];
+      Temp phi_src = phi->operands[i].getTemp();
+
+      assert(phi_src.regClass().type() == RegType::sgpr);
+      Temp tmp = bld.tmp(RegClass(RegType::vgpr, phi_src.size()));
+      insert_before_logical_end(pred, bld.pseudo(aco_opcode::p_create_vector, Definition(tmp), phi_src).get_ptr());
+      Temp new_phi_src = bld.tmp(phi->definitions[0].regClass());
+      insert_before_logical_end(pred, bld.pseudo(aco_opcode::p_extract_vector, Definition(new_phi_src), tmp, Operand(0u)).get_ptr());
+
+      phi->operands[i].setTemp(new_phi_src);
+   }
+   return;
+}
+
 void lower_bool_phis(Program* program)
 {
    for (Block& block : program->blocks) {
@@ -197,6 +221,8 @@ void lower_bool_phis(Program* program)
             assert(program->wave_size == 64 ? phi->definitions[0].regClass() != s1 : phi->definitions[0].regClass() != s2);
             if (phi->definitions[0].regClass() == program->lane_mask)
                lower_divergent_bool_phi(program, &block, phi);
+            else if (phi->definitions[0].regClass().is_subdword())
+               lower_subdword_phis(program, &block, phi);
          } else if (!is_phi(phi)) {
             break;
          }