Mesa (main): aco: swap multiplication operands if needed to create v_fmac_f32/etc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Dec 13 12:36:37 UTC 2021


Module: Mesa
Branch: main
Commit: c5f02a1cd3b110bafff0fc55064938604bf539ee
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c5f02a1cd3b110bafff0fc55064938604bf539ee

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Wed Jan 13 16:35:01 2021 +0000

aco: swap multiplication operands if needed to create v_fmac_f32/etc

For v_pk_fma_f32 and v_fma_f32 from nir_op_ffma, we don't try to put
scalars in the first operand.

No fossil-db changes.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9805>

---

 src/amd/compiler/aco_register_allocation.cpp | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp
index 1eadb916ccf..530d7d2e177 100644
--- a/src/amd/compiler/aco_register_allocation.cpp
+++ b/src/amd/compiler/aco_register_allocation.cpp
@@ -2580,10 +2580,17 @@ register_allocation(Program* program, std::vector<IDSet>& live_out_per_block, ra
               (instr->opcode == aco_opcode::v_pk_fma_f16 && program->chip_class >= GFX10) ||
               (instr->opcode == aco_opcode::v_dot4_i32_i8 && program->family != CHIP_VEGA20)) &&
              instr->operands[2].isTemp() && instr->operands[2].isKillBeforeDef() &&
-             instr->operands[2].getTemp().type() == RegType::vgpr && instr->operands[1].isTemp() &&
-             instr->operands[1].getTemp().type() == RegType::vgpr && !instr->usesModifiers() &&
-             instr->operands[0].physReg().byte() == 0 && instr->operands[1].physReg().byte() == 0 &&
-             instr->operands[2].physReg().byte() == 0) {
+             instr->operands[2].getTemp().type() == RegType::vgpr &&
+             ((instr->operands[0].isTemp() &&
+               instr->operands[0].getTemp().type() == RegType::vgpr) ||
+              (instr->operands[1].isTemp() &&
+               instr->operands[1].getTemp().type() == RegType::vgpr)) &&
+             !instr->usesModifiers() && instr->operands[0].physReg().byte() == 0 &&
+             instr->operands[1].physReg().byte() == 0 && instr->operands[2].physReg().byte() == 0) {
+            if (!instr->operands[1].isTemp() ||
+                instr->operands[1].getTemp().type() != RegType::vgpr)
+               std::swap(instr->operands[0], instr->operands[1]);
+
             unsigned def_id = instr->definitions[0].tempId();
             bool use_vop2 = true;
             if (ctx.assignments[def_id].affinity) {



More information about the mesa-commit mailing list