2019-09-17 13:22:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Valve Corporation
|
|
|
|
|
*
|
2024-04-08 09:02:30 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2019-09-17 13:22:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-06-30 15:33:18 +01:00
|
|
|
#include "aco_builder.h"
|
2019-09-17 13:22:17 +02:00
|
|
|
#include "aco_ir.h"
|
2021-06-09 10:14:54 +02:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
#include "util/half_float.h"
|
2020-08-04 10:58:11 -07:00
|
|
|
#include "util/memstream.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <vector>
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
namespace aco {
|
|
|
|
|
|
2024-06-15 16:17:29 +02:00
|
|
|
namespace {
|
2019-09-17 13:22:17 +02:00
|
|
|
/**
|
|
|
|
|
* The optimizer works in 4 phases:
|
|
|
|
|
* (1) The first pass collects information for each ssa-def,
|
|
|
|
|
* propagates reg->reg operands of the same type, inline constants
|
|
|
|
|
* and neg/abs input modifiers.
|
|
|
|
|
* (2) The second pass combines instructions like mad, omod, clamp and
|
|
|
|
|
* propagates sgpr's on VALU instructions.
|
|
|
|
|
* This pass depends on information collected in the first pass.
|
|
|
|
|
* (3) The third pass goes backwards, and selects instructions,
|
|
|
|
|
* i.e. decides if a mad instruction is profitable and eliminates dead code.
|
|
|
|
|
* (4) The fourth pass cleans up the sequence: literals get applied and dead
|
|
|
|
|
* instructions are removed from the sequence.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct mad_info {
|
|
|
|
|
aco_ptr<Instruction> add_instr;
|
|
|
|
|
uint32_t mul_temp_id;
|
|
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
mad_info(aco_ptr<Instruction> instr, uint32_t id) : add_instr(std::move(instr)), mul_temp_id(id)
|
2020-09-22 17:51:06 -07:00
|
|
|
{}
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum Label {
|
2020-05-15 16:28:03 +01:00
|
|
|
label_constant_32bit = 1 << 1,
|
2020-05-15 15:12:33 +01:00
|
|
|
/* label_{abs,neg,mul,omod2,omod4,omod5,clamp} are used for both 16 and
|
|
|
|
|
* 32-bit operations but this shouldn't cause any issues because we don't
|
|
|
|
|
* look through any conversions */
|
2019-09-17 13:22:17 +02:00
|
|
|
label_abs = 1 << 2,
|
|
|
|
|
label_neg = 1 << 3,
|
|
|
|
|
label_temp = 1 << 5,
|
|
|
|
|
label_literal = 1 << 6,
|
|
|
|
|
label_mad = 1 << 7,
|
|
|
|
|
label_omod2 = 1 << 8,
|
|
|
|
|
label_omod4 = 1 << 9,
|
|
|
|
|
label_omod5 = 1 << 10,
|
|
|
|
|
label_clamp = 1 << 12,
|
|
|
|
|
label_b2f = 1 << 16,
|
2025-07-15 16:20:15 +01:00
|
|
|
/* This label means that it's either 0 or -1, and the ssa_info::temp is an s1 which is 0 or 1. */
|
2019-11-05 11:41:00 +01:00
|
|
|
label_uniform_bool = 1 << 21,
|
2019-11-13 11:14:51 +01:00
|
|
|
label_constant_64bit = 1 << 22,
|
2025-07-15 16:20:15 +01:00
|
|
|
/* This label is added to the first definition of s_not/s_or/s_xor/s_and when all operands are
|
|
|
|
|
* uniform_bool or uniform_bitwise. The first definition of ssa_info::instr would be 0 or -1 and
|
|
|
|
|
* the second is SCC.
|
|
|
|
|
*/
|
2020-01-03 10:30:04 +01:00
|
|
|
label_uniform_bitwise = 1 << 23,
|
2025-07-15 16:20:15 +01:00
|
|
|
/* This label means that it's either 0 or 1 and ssa_info::temp is the inverse. */
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
label_scc_invert = 1 << 24,
|
2020-01-16 19:32:31 +01:00
|
|
|
label_scc_needed = 1 << 26,
|
2020-04-02 17:41:36 +02:00
|
|
|
label_b2i = 1 << 27,
|
2020-06-17 15:02:30 +01:00
|
|
|
label_fcanonicalize = 1 << 28,
|
2020-05-15 16:28:03 +01:00
|
|
|
label_constant_16bit = 1 << 29,
|
2024-07-15 18:53:19 +02:00
|
|
|
label_canonicalized = 1ull << 32, /* 1ull to prevent sign extension */
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
label_extract = 1ull << 33,
|
|
|
|
|
label_insert = 1ull << 34,
|
2022-01-17 16:52:10 +00:00
|
|
|
label_f2f16 = 1ull << 38,
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
static constexpr uint64_t instr_mod_labels =
|
2022-01-17 16:52:10 +00:00
|
|
|
label_omod2 | label_omod4 | label_omod5 | label_clamp | label_insert | label_f2f16;
|
2020-08-12 15:58:32 +01:00
|
|
|
|
2024-05-17 17:50:15 +02:00
|
|
|
static constexpr uint64_t temp_labels = label_abs | label_neg | label_temp | label_b2f |
|
2020-06-17 15:02:30 +01:00
|
|
|
label_uniform_bool | label_scc_invert | label_b2i |
|
|
|
|
|
label_fcanonicalize;
|
2020-06-01 11:27:53 +01:00
|
|
|
static constexpr uint32_t val_labels =
|
2023-05-03 12:48:01 +02:00
|
|
|
label_constant_32bit | label_constant_64bit | label_constant_16bit | label_literal | label_mad;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-07-30 15:43:44 +02:00
|
|
|
static_assert((instr_mod_labels & temp_labels) == 0, "labels cannot intersect");
|
|
|
|
|
static_assert((instr_mod_labels & val_labels) == 0, "labels cannot intersect");
|
2020-08-12 13:52:55 +01:00
|
|
|
static_assert((temp_labels & val_labels) == 0, "labels cannot intersect");
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
struct ssa_info {
|
2020-06-01 11:27:53 +01:00
|
|
|
uint64_t label;
|
2019-09-17 13:22:17 +02:00
|
|
|
union {
|
2020-06-01 11:27:53 +01:00
|
|
|
uint32_t val;
|
2019-09-17 13:22:17 +02:00
|
|
|
Temp temp;
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* mod_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
2024-07-24 12:28:36 +02:00
|
|
|
Instruction* parent_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2020-04-06 14:08:39 +01:00
|
|
|
ssa_info() : label(0) {}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void add_label(Label new_label)
|
|
|
|
|
{
|
2020-08-12 15:58:32 +01:00
|
|
|
if (new_label & instr_mod_labels) {
|
2024-07-30 15:43:44 +02:00
|
|
|
label &= ~instr_mod_labels;
|
2020-06-01 11:27:53 +01:00
|
|
|
label &= ~(temp_labels | val_labels); /* instr, temp and val alias */
|
2020-08-12 15:58:32 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
if (new_label & temp_labels) {
|
|
|
|
|
label &= ~temp_labels;
|
2024-07-30 15:43:44 +02:00
|
|
|
label &= ~(instr_mod_labels | val_labels); /* instr, temp and val alias */
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-15 16:28:03 +01:00
|
|
|
uint32_t const_labels =
|
|
|
|
|
label_literal | label_constant_32bit | label_constant_64bit | label_constant_16bit;
|
2020-06-01 11:27:53 +01:00
|
|
|
if (new_label & const_labels) {
|
2020-05-15 16:28:03 +01:00
|
|
|
label &= ~val_labels | const_labels;
|
2024-07-30 15:43:44 +02:00
|
|
|
label &= ~(instr_mod_labels | temp_labels); /* instr, temp and val alias */
|
2020-06-01 11:27:53 +01:00
|
|
|
} else if (new_label & val_labels) {
|
2019-09-17 13:22:17 +02:00
|
|
|
label &= ~val_labels;
|
2024-07-30 15:43:44 +02:00
|
|
|
label &= ~(instr_mod_labels | temp_labels); /* instr, temp and val alias */
|
2020-06-01 11:27:53 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
label |= new_label;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
void set_constant(amd_gfx_level gfx_level, uint64_t constant)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2021-07-13 11:22:46 +02:00
|
|
|
Operand op16 = Operand::c16(constant);
|
2022-05-12 02:50:17 -04:00
|
|
|
Operand op32 = Operand::get_const(gfx_level, constant, 4);
|
2020-05-15 16:28:03 +01:00
|
|
|
add_label(label_literal);
|
2019-09-17 13:22:17 +02:00
|
|
|
val = constant;
|
|
|
|
|
|
2021-07-19 15:01:09 +02:00
|
|
|
/* check that no upper bits are lost in case of packed 16bit constants */
|
2022-04-29 16:45:17 +01:00
|
|
|
if (gfx_level >= GFX8 && !op16.isLiteral() &&
|
|
|
|
|
op16.constantValue16(true) == ((constant >> 16) & 0xffff))
|
2020-05-15 16:28:03 +01:00
|
|
|
add_label(label_constant_16bit);
|
|
|
|
|
|
2020-12-03 15:18:30 +00:00
|
|
|
if (!op32.isLiteral())
|
2020-05-15 16:28:03 +01:00
|
|
|
add_label(label_constant_32bit);
|
|
|
|
|
|
2020-12-03 15:18:30 +00:00
|
|
|
if (Operand::is_constant_representable(constant, 8))
|
2020-05-15 16:28:03 +01:00
|
|
|
add_label(label_constant_64bit);
|
|
|
|
|
|
|
|
|
|
if (label & label_constant_64bit) {
|
2021-07-13 11:22:46 +02:00
|
|
|
val = Operand::c64(constant).constantValue();
|
2020-05-15 16:28:03 +01:00
|
|
|
if (val != constant)
|
|
|
|
|
label &= ~(label_literal | label_constant_16bit | label_constant_32bit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_constant(unsigned bits)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2020-05-15 16:28:03 +01:00
|
|
|
switch (bits) {
|
|
|
|
|
case 8: return label & label_literal;
|
|
|
|
|
case 16: return label & label_constant_16bit;
|
|
|
|
|
case 32: return label & label_constant_32bit;
|
|
|
|
|
case 64: return label & label_constant_64bit;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-15 16:28:03 +01:00
|
|
|
bool is_literal(unsigned bits)
|
2019-11-13 11:14:51 +01:00
|
|
|
{
|
2020-05-15 16:28:03 +01:00
|
|
|
bool is_lit = label & label_literal;
|
|
|
|
|
switch (bits) {
|
|
|
|
|
case 8: return false;
|
|
|
|
|
case 16: return is_lit && ~(label & label_constant_16bit);
|
|
|
|
|
case 32: return is_lit && ~(label & label_constant_32bit);
|
|
|
|
|
case 64: return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2019-11-13 11:14:51 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-15 16:28:03 +01:00
|
|
|
bool is_constant_or_literal(unsigned bits)
|
2019-11-13 11:14:51 +01:00
|
|
|
{
|
2020-05-15 16:28:03 +01:00
|
|
|
if (bits == 64)
|
|
|
|
|
return label & label_constant_64bit;
|
|
|
|
|
else
|
|
|
|
|
return label & label_literal;
|
2019-11-13 11:14:51 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void set_abs(Temp abs_temp)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_abs);
|
|
|
|
|
temp = abs_temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_abs() { return label & label_abs; }
|
|
|
|
|
|
|
|
|
|
void set_neg(Temp neg_temp)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_neg);
|
|
|
|
|
temp = neg_temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_neg() { return label & label_neg; }
|
|
|
|
|
|
|
|
|
|
void set_neg_abs(Temp neg_abs_temp)
|
|
|
|
|
{
|
|
|
|
|
add_label((Label)((uint32_t)label_abs | (uint32_t)label_neg));
|
|
|
|
|
temp = neg_abs_temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_temp(Temp tmp)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_temp);
|
|
|
|
|
temp = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_temp() { return label & label_temp; }
|
|
|
|
|
|
2023-05-03 12:48:01 +02:00
|
|
|
void set_mad(uint32_t mad_info_idx)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
add_label(label_mad);
|
2023-05-03 12:48:01 +02:00
|
|
|
val = mad_info_idx;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_mad() { return label & label_mad; }
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
void set_omod2(Instruction* mul)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
add_label(label_omod2);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = mul;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_omod2() { return label & label_omod2; }
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
void set_omod4(Instruction* mul)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
add_label(label_omod4);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = mul;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_omod4() { return label & label_omod4; }
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
void set_omod5(Instruction* mul)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
add_label(label_omod5);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = mul;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_omod5() { return label & label_omod5; }
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
void set_clamp(Instruction* med3)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
add_label(label_clamp);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = med3;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_clamp() { return label & label_clamp; }
|
|
|
|
|
|
2022-01-17 16:52:10 +00:00
|
|
|
void set_f2f16(Instruction* conv)
|
|
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
2022-01-17 16:52:10 +00:00
|
|
|
add_label(label_f2f16);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = conv;
|
2022-01-17 16:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_f2f16() { return label & label_f2f16; }
|
|
|
|
|
|
2020-11-03 14:40:05 +01:00
|
|
|
void set_b2f(Temp b2f_val)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
add_label(label_b2f);
|
2020-11-03 14:40:05 +01:00
|
|
|
temp = b2f_val;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_b2f() { return label & label_b2f; }
|
|
|
|
|
|
2020-01-03 10:30:04 +01:00
|
|
|
void set_uniform_bitwise() { add_label(label_uniform_bitwise); }
|
|
|
|
|
|
|
|
|
|
bool is_uniform_bitwise() { return label & label_uniform_bitwise; }
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
void set_scc_needed() { add_label(label_scc_needed); }
|
|
|
|
|
|
|
|
|
|
bool is_scc_needed() { return label & label_scc_needed; }
|
|
|
|
|
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
void set_scc_invert(Temp scc_inv)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_scc_invert);
|
|
|
|
|
temp = scc_inv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_scc_invert() { return label & label_scc_invert; }
|
|
|
|
|
|
2019-11-05 11:41:00 +01:00
|
|
|
void set_uniform_bool(Temp uniform_bool)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_uniform_bool);
|
|
|
|
|
temp = uniform_bool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_uniform_bool() { return label & label_uniform_bool; }
|
|
|
|
|
|
2020-11-03 14:40:05 +01:00
|
|
|
void set_b2i(Temp b2i_val)
|
2020-04-02 17:41:36 +02:00
|
|
|
{
|
|
|
|
|
add_label(label_b2i);
|
2020-11-03 14:40:05 +01:00
|
|
|
temp = b2i_val;
|
2020-04-02 17:41:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_b2i() { return label & label_b2i; }
|
|
|
|
|
|
2020-06-17 15:02:30 +01:00
|
|
|
void set_fcanonicalize(Temp tmp)
|
|
|
|
|
{
|
|
|
|
|
add_label(label_fcanonicalize);
|
|
|
|
|
temp = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_fcanonicalize() { return label & label_fcanonicalize; }
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
void set_canonicalized() { add_label(label_canonicalized); }
|
|
|
|
|
|
|
|
|
|
bool is_canonicalized() { return label & label_canonicalized; }
|
|
|
|
|
|
2024-07-30 15:43:44 +02:00
|
|
|
void set_extract() { add_label(label_extract); }
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
|
|
|
|
bool is_extract() { return label & label_extract; }
|
|
|
|
|
|
|
|
|
|
void set_insert(Instruction* insert)
|
|
|
|
|
{
|
2023-09-22 19:08:18 +02:00
|
|
|
if (label & temp_labels)
|
|
|
|
|
return;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
add_label(label_insert);
|
2024-07-23 17:49:32 +02:00
|
|
|
mod_instr = insert;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_insert() { return label & label_insert; }
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct opt_ctx {
|
|
|
|
|
Program* program;
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
float_mode fp_mode;
|
2019-09-17 13:22:17 +02:00
|
|
|
std::vector<aco_ptr<Instruction>> instructions;
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
std::vector<ssa_info> info;
|
2019-09-17 13:22:17 +02:00
|
|
|
std::pair<uint32_t, Temp> last_literal;
|
|
|
|
|
std::vector<mad_info> mad_infos;
|
|
|
|
|
std::vector<uint16_t> uses;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-27 21:20:39 +01:00
|
|
|
aco_type
|
|
|
|
|
get_canonical_operand_type(aco_opcode opcode, unsigned idx)
|
|
|
|
|
{
|
|
|
|
|
aco_type type = instr_info.alu_opcode_infos[(int)opcode].op_types[idx];
|
|
|
|
|
|
|
|
|
|
if (type.bit_size == 8 && type.num_components > 1) {
|
|
|
|
|
/* Handling packed fp8/bf8 as non vector is easier. */
|
|
|
|
|
type.bit_size *= type.num_components;
|
|
|
|
|
type.num_components = 1;
|
|
|
|
|
type.base_type = aco_base_type_none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
dpp16_ctrl_uses_bc(uint16_t dpp_ctrl)
|
|
|
|
|
{
|
|
|
|
|
if (dpp_ctrl >= dpp_row_sl(1) && dpp_ctrl <= dpp_row_sl(15))
|
|
|
|
|
return true;
|
|
|
|
|
if (dpp_ctrl >= dpp_row_sr(1) && dpp_ctrl <= dpp_row_sr(15))
|
|
|
|
|
return true;
|
|
|
|
|
if (dpp_ctrl == dpp_wf_sl1 || dpp_ctrl == dpp_wf_sr1)
|
|
|
|
|
return true;
|
|
|
|
|
if (dpp_ctrl == dpp_row_bcast15 || dpp_ctrl == dpp_row_bcast31)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct alu_opt_op {
|
|
|
|
|
Operand op;
|
|
|
|
|
SubdwordSel extract[2] = {SubdwordSel::dword, SubdwordSel::dword};
|
|
|
|
|
union {
|
|
|
|
|
uint16_t _modifiers = 0;
|
|
|
|
|
bitfield_array8<uint16_t, 0, 2> neg;
|
|
|
|
|
bitfield_array8<uint16_t, 2, 2> abs;
|
|
|
|
|
bitfield_bool<uint16_t, 4> f16_to_f32;
|
|
|
|
|
bitfield_bool<uint16_t, 5> dot_sext;
|
|
|
|
|
bitfield_bool<uint16_t, 6> dpp16;
|
|
|
|
|
bitfield_bool<uint16_t, 7> dpp8;
|
|
|
|
|
bitfield_bool<uint16_t, 8> bc;
|
|
|
|
|
bitfield_bool<uint16_t, 9> fi;
|
|
|
|
|
};
|
|
|
|
|
uint32_t dpp_ctrl = 0;
|
|
|
|
|
|
|
|
|
|
alu_opt_op& operator=(const alu_opt_op& other)
|
|
|
|
|
{
|
|
|
|
|
memmove((void*)this, &other, sizeof(*this));
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alu_opt_op() = default;
|
|
|
|
|
alu_opt_op(Operand _op) : op(_op) {};
|
|
|
|
|
alu_opt_op(const alu_opt_op& other) { *this = other; }
|
|
|
|
|
|
|
|
|
|
uint64_t constant_after_mods(opt_ctx& ctx, aco_type type) const
|
|
|
|
|
{
|
|
|
|
|
assert(this->op.isConstant());
|
|
|
|
|
uint64_t res = 0;
|
|
|
|
|
for (unsigned comp = 0; comp < type.num_components; comp++) {
|
|
|
|
|
uint64_t part = this->op.constantValue64();
|
|
|
|
|
/* 16bit negative int inline constants are sign extended, constantValue16 handles that. */
|
|
|
|
|
if (this->op.bytes() == 2)
|
|
|
|
|
part = this->op.constantValue16(false) | (this->op.constantValue16(true) << 16);
|
|
|
|
|
|
|
|
|
|
if (type.bytes() <= 4) {
|
|
|
|
|
SubdwordSel sel = this->extract[comp];
|
|
|
|
|
part = part >> (sel.offset() * 8);
|
|
|
|
|
if (sel.size() < 4) {
|
|
|
|
|
part &= BITFIELD_MASK(sel.size() * 8);
|
|
|
|
|
part = sel.sign_extend() ? util_sign_extend(part, sel.size() * 8) : part;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this->f16_to_f32) {
|
|
|
|
|
if (!(ctx.fp_mode.denorm16_64 & fp_denorm_keep_in)) {
|
|
|
|
|
uint32_t absv = part & 0x7fff;
|
|
|
|
|
if (absv <= 0x3ff)
|
|
|
|
|
part &= 0x8000;
|
|
|
|
|
}
|
|
|
|
|
part = fui(_mesa_half_to_float(part));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
part &= BITFIELD64_MASK(type.bit_size - this->abs[comp]);
|
|
|
|
|
part ^= this->neg[comp] ? BITFIELD64_BIT(type.bit_size - 1) : 0;
|
|
|
|
|
res |= part << (type.bit_size * comp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct alu_opt_info {
|
|
|
|
|
aco::small_vec<Definition, 2> defs;
|
|
|
|
|
aco::small_vec<alu_opt_op, 5> operands;
|
|
|
|
|
aco_opcode opcode;
|
|
|
|
|
Format format;
|
|
|
|
|
uint32_t imm;
|
|
|
|
|
uint32_t pass_flags; /* exec id */
|
|
|
|
|
|
|
|
|
|
/* defs[0] modifiers */
|
|
|
|
|
uint8_t omod;
|
|
|
|
|
bool clamp;
|
|
|
|
|
bool f32_to_f16;
|
|
|
|
|
SubdwordSel insert;
|
|
|
|
|
|
|
|
|
|
bool try_swap_operands(unsigned idx0, unsigned idx1)
|
|
|
|
|
{
|
|
|
|
|
aco_opcode new_opcode = get_swapped_opcode(opcode, idx0, idx1);
|
|
|
|
|
if (new_opcode != aco_opcode::num_opcodes) {
|
|
|
|
|
opcode = new_opcode;
|
|
|
|
|
std::swap(operands[idx0], operands[idx1]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
at_most_6lsb_used(aco_opcode op, unsigned idx)
|
|
|
|
|
{
|
|
|
|
|
if (op == aco_opcode::v_writelane_b32 || op == aco_opcode::v_writelane_b32_e64 ||
|
|
|
|
|
op == aco_opcode::v_readlane_b32 || op == aco_opcode::v_readlane_b32_e64)
|
|
|
|
|
return idx == 1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
bytes_used(opt_ctx& ctx, alu_opt_info& info, unsigned idx)
|
|
|
|
|
{
|
|
|
|
|
unsigned used = 4;
|
|
|
|
|
aco_type type = get_canonical_operand_type(info.opcode, idx);
|
|
|
|
|
if (type.bytes() == 0)
|
|
|
|
|
return 4;
|
|
|
|
|
used = MIN2(used, type.bytes());
|
|
|
|
|
if (info.opcode == aco_opcode::v_lshlrev_b32 && idx == 1 && info.operands[0].op.isConstant()) {
|
|
|
|
|
unsigned shift = info.operands[0].op.constantValue() & 0x1f;
|
|
|
|
|
if (shift >= 16)
|
|
|
|
|
used = MIN2(used, 2);
|
|
|
|
|
if (shift >= 24)
|
|
|
|
|
used = MIN2(used, 1);
|
|
|
|
|
}
|
|
|
|
|
return used;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
optimize_constants(opt_ctx& ctx, alu_opt_info& info)
|
|
|
|
|
{
|
|
|
|
|
/* inline constants, pack literals */
|
|
|
|
|
uint32_t literal = 0;
|
|
|
|
|
unsigned litbits_used = 0;
|
|
|
|
|
bool force_f2f32 = false;
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
auto& op_info = info.operands[i];
|
|
|
|
|
assert(!op_info.op.isUndefined());
|
|
|
|
|
if (!op_info.op.isConstant())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
aco_type type = get_canonical_operand_type(info.opcode, i);
|
|
|
|
|
|
|
|
|
|
if (type.num_components != 1 && type.num_components != 2)
|
|
|
|
|
return false;
|
|
|
|
|
if (!type.constant_bits())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (type.bytes() > 4)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* remove modifiers on constants: apply extract, f2f32, abs, neg */
|
|
|
|
|
assert(op_info.op.size() == 1);
|
|
|
|
|
uint32_t constant = op_info.constant_after_mods(ctx, type);
|
|
|
|
|
op_info.op = Operand();
|
|
|
|
|
for (unsigned comp = 0; comp < type.num_components; comp++) {
|
|
|
|
|
op_info.extract[comp] = SubdwordSel(type.bit_size / 8, comp * type.bit_size / 8, false);
|
|
|
|
|
op_info.f16_to_f32 = false;
|
|
|
|
|
op_info.neg[comp] = false;
|
|
|
|
|
op_info.abs[comp] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (at_most_6lsb_used(info.opcode, i))
|
|
|
|
|
constant &= 0x3f;
|
|
|
|
|
|
|
|
|
|
bool can_use_mods = can_use_input_modifiers(ctx.program->gfx_level, info.opcode, i);
|
|
|
|
|
|
|
|
|
|
/* inline constants */
|
|
|
|
|
if (type.num_components == 1) {
|
|
|
|
|
Operand new_op =
|
|
|
|
|
Operand::get_const(ctx.program->gfx_level, constant, type.constant_bits() / 8);
|
|
|
|
|
Operand neg_op =
|
|
|
|
|
Operand::get_const(ctx.program->gfx_level, BITFIELD_BIT(type.bit_size - 1) ^ constant,
|
|
|
|
|
type.constant_bits() / 8);
|
|
|
|
|
Operand sext_op = Operand::get_const(ctx.program->gfx_level, 0xffff0000 | constant,
|
|
|
|
|
type.constant_bits() / 8);
|
|
|
|
|
if (!new_op.isLiteral()) {
|
|
|
|
|
op_info.op = new_op;
|
|
|
|
|
} else if (can_use_mods && !neg_op.isLiteral()) {
|
|
|
|
|
op_info.op = neg_op;
|
|
|
|
|
op_info.neg[0] = true;
|
|
|
|
|
} else if (type.bit_size == 16 && !sext_op.isLiteral()) {
|
|
|
|
|
op_info.op = sext_op;
|
|
|
|
|
}
|
|
|
|
|
// TODO opsel?
|
|
|
|
|
} else if (info.format == Format::VOP3P) {
|
|
|
|
|
assert(!can_use_mods || type.constant_bits() == 16);
|
|
|
|
|
unsigned num_methods = (type.constant_bits() == 32 ? 5 : 1);
|
|
|
|
|
for (unsigned hi = 0; op_info.op.isUndefined() && hi < 2; hi++) {
|
|
|
|
|
for (unsigned negate = 0;
|
|
|
|
|
op_info.op.isUndefined() && (negate <= unsigned(can_use_mods)); negate++) {
|
|
|
|
|
for (unsigned method = 0; op_info.op.isUndefined() && method < num_methods;
|
|
|
|
|
method++) {
|
|
|
|
|
uint32_t candidate = ((constant >> (hi * 16)) & 0xffff) ^ (negate ? 0x8000 : 0);
|
|
|
|
|
switch (method) {
|
|
|
|
|
case 0: break; /* try directly as constant */
|
|
|
|
|
case 1: candidate |= 0xffff0000; break; /* sign extend */
|
|
|
|
|
case 2: candidate |= 0x3e220000; break; /* 0.5pi */
|
|
|
|
|
case 3: candidate = (candidate << 16); break; /* high half */
|
|
|
|
|
case 4: candidate = (candidate << 16) | 0xf983; break; /* high half, 0.5pi. */
|
|
|
|
|
default: UNREACHABLE("impossible");
|
|
|
|
|
}
|
|
|
|
|
Operand new_op = Operand::get_const(ctx.program->gfx_level, candidate,
|
|
|
|
|
type.constant_bits() / 8);
|
|
|
|
|
if (new_op.isLiteral())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for (unsigned opsel = 0; op_info.op.isUndefined() && opsel < 2; opsel++) {
|
|
|
|
|
uint16_t other = constant >> (!hi * 16);
|
|
|
|
|
uint16_t abs_mask = 0xffffu >> unsigned(can_use_mods);
|
|
|
|
|
if ((new_op.constantValue16(opsel) & abs_mask) != (other & abs_mask))
|
|
|
|
|
continue;
|
|
|
|
|
op_info.op = new_op;
|
|
|
|
|
op_info.extract[hi] = method >= 3 ? SubdwordSel::uword1 : SubdwordSel::uword0;
|
|
|
|
|
op_info.extract[!hi] = opsel ? SubdwordSel::uword1 : SubdwordSel::uword0;
|
|
|
|
|
op_info.neg[hi] = negate;
|
|
|
|
|
op_info.neg[!hi] = new_op.constantValue16(opsel) ^ other;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* we found an inline constant */
|
|
|
|
|
if (!op_info.op.isUndefined())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool use_swizzle = type.num_components == 2 && info.format == Format::VOP3P;
|
|
|
|
|
bool try_neg = can_use_mods && (type.num_components == 1 || use_swizzle);
|
|
|
|
|
unsigned comp_bits = use_swizzle ? type.bit_size : type.bytes() * 8;
|
|
|
|
|
assert(comp_bits == 32 || comp_bits == 16);
|
|
|
|
|
uint32_t abs_mask = BITFIELD_MASK(comp_bits - try_neg);
|
|
|
|
|
for (unsigned comp = 0; comp <= unsigned(use_swizzle); comp++) {
|
|
|
|
|
uint32_t part = constant >> (comp * comp_bits) & BITFIELD_MASK(comp_bits);
|
|
|
|
|
|
|
|
|
|
/* Try to re-use another literal, or part of it. */
|
|
|
|
|
bool found_part = false;
|
|
|
|
|
for (unsigned litcomp = 0; litcomp < (litbits_used / comp_bits); litcomp++) {
|
|
|
|
|
uint32_t litpart = literal >> (litcomp * comp_bits) & BITFIELD_MASK(comp_bits);
|
|
|
|
|
if ((litpart & abs_mask) == (part & abs_mask)) {
|
|
|
|
|
op_info.neg[comp] = litpart ^ part;
|
|
|
|
|
op_info.extract[comp] = SubdwordSel(comp_bits / 8, litcomp * (comp_bits / 8), false);
|
|
|
|
|
found_part = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found_part)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If there isn't enough space for more literal data, try to use fp16 or return false. */
|
|
|
|
|
litbits_used = align(litbits_used, comp_bits);
|
|
|
|
|
if (litbits_used + comp_bits > 32) {
|
|
|
|
|
if (comp_bits == 32 && !force_f2f32) {
|
|
|
|
|
float f32s[] = {uif(literal), uif(constant)};
|
|
|
|
|
literal = 0;
|
|
|
|
|
for (unsigned fltidx = 0; fltidx < 2; fltidx++) {
|
|
|
|
|
uint32_t fp16_val = _mesa_float_to_half(f32s[fltidx]);
|
|
|
|
|
bool is_denorm = (fp16_val & 0x7fff) != 0 && (fp16_val & 0x7fff) <= 0x3ff;
|
|
|
|
|
if (_mesa_half_to_float(fp16_val) != f32s[fltidx] ||
|
|
|
|
|
(is_denorm && !(ctx.fp_mode.denorm16_64 & fp_denorm_keep_in)))
|
|
|
|
|
return false;
|
|
|
|
|
literal |= fp16_val << (fltidx * 16);
|
|
|
|
|
}
|
|
|
|
|
force_f2f32 = true;
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
literal |= part << litbits_used;
|
|
|
|
|
op_info.extract[comp] = SubdwordSel(comp_bits / 8, litbits_used / 8, false);
|
|
|
|
|
litbits_used += comp_bits;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& op_info : info.operands) {
|
|
|
|
|
if (!op_info.op.isUndefined())
|
|
|
|
|
continue;
|
|
|
|
|
op_info.op = Operand::literal32(literal);
|
|
|
|
|
op_info.f16_to_f32 = force_f2f32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Format
|
|
|
|
|
format_combine(Format f1, Format f2)
|
|
|
|
|
{
|
|
|
|
|
return (Format)((uint32_t)f1 | (uint32_t)f2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
format_is(Format f1, Format f2)
|
|
|
|
|
{
|
|
|
|
|
return ((Format)((uint32_t)f1 & (uint32_t)f2)) == f2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Determine if this alu_opt_info can be represented by a valid ACO IR instruction.
|
|
|
|
|
* info is modified to not duplicate work when it's converted to an ACO IR instruction.
|
|
|
|
|
* If false is returned, info must no longer be used.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
alu_opt_info_is_valid(opt_ctx& ctx, alu_opt_info& info)
|
|
|
|
|
{
|
|
|
|
|
info.format = instr_info.format[(int)info.opcode];
|
|
|
|
|
|
|
|
|
|
/* remove dpp if possible, abort in some unsupported cases (bc with sgpr, constant.) */
|
|
|
|
|
for (auto& op_info : info.operands) {
|
|
|
|
|
if (!op_info.dpp16 && !op_info.dpp8)
|
|
|
|
|
continue;
|
|
|
|
|
if (op_info.op.isOfType(RegType::vgpr))
|
|
|
|
|
continue;
|
|
|
|
|
/* bc=0: undefined if inactive read (lane disabled, but that's not expressed in SSA)
|
|
|
|
|
* if fi=1, bc only matters for a few dpp16 options
|
|
|
|
|
*/
|
|
|
|
|
if (op_info.bc && (!op_info.fi || (op_info.dpp16 && dpp16_ctrl_uses_bc(op_info.dpp_ctrl))))
|
|
|
|
|
return false;
|
|
|
|
|
op_info.dpp16 = false;
|
|
|
|
|
op_info.dpp8 = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if mul, push neg to constant, eliminate double negate */
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::v_mul_f64_e64:
|
|
|
|
|
case aco_opcode::v_mul_f64:
|
|
|
|
|
case aco_opcode::v_mul_f32:
|
|
|
|
|
case aco_opcode::v_mul_legacy_f32:
|
|
|
|
|
case aco_opcode::v_mul_f16:
|
|
|
|
|
case aco_opcode::v_mad_f32:
|
|
|
|
|
case aco_opcode::v_mad_legacy_f32:
|
|
|
|
|
case aco_opcode::v_mad_f16:
|
|
|
|
|
case aco_opcode::v_mad_legacy_f16:
|
|
|
|
|
case aco_opcode::v_fma_f64:
|
|
|
|
|
case aco_opcode::v_fma_f32:
|
|
|
|
|
case aco_opcode::v_fma_legacy_f32:
|
|
|
|
|
case aco_opcode::v_fma_f16:
|
|
|
|
|
case aco_opcode::v_fma_legacy_f16:
|
|
|
|
|
case aco_opcode::v_fma_mix_f32:
|
|
|
|
|
case aco_opcode::v_fma_mixlo_f16:
|
|
|
|
|
case aco_opcode::v_pk_mul_f16:
|
|
|
|
|
case aco_opcode::v_pk_fma_f16:
|
|
|
|
|
case aco_opcode::s_mul_f32:
|
|
|
|
|
case aco_opcode::s_mul_f16:
|
|
|
|
|
case aco_opcode::s_fmac_f32:
|
|
|
|
|
case aco_opcode::s_fmac_f16:
|
|
|
|
|
for (unsigned comp = 0; comp < 2; comp++) {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (info.operands[!i].op.isConstant() || info.operands[!i].neg[comp]) {
|
|
|
|
|
info.operands[!i].neg[comp] ^= info.operands[i].neg[comp];
|
|
|
|
|
info.operands[i].neg[comp] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!optimize_constants(ctx, info))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* check constant bus limit */
|
|
|
|
|
bool is_salu = false;
|
|
|
|
|
switch (info.format) {
|
|
|
|
|
case Format::SOPC:
|
|
|
|
|
case Format::SOPK:
|
|
|
|
|
case Format::SOP1:
|
|
|
|
|
case Format::SOP2:
|
|
|
|
|
case Format::SOPP: is_salu = true; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
int constant_limit = is_salu ? INT_MAX : (ctx.program->gfx_level >= GFX10 ? 2 : 1);
|
|
|
|
|
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::v_writelane_b32:
|
|
|
|
|
case aco_opcode::v_writelane_b32_e64: constant_limit = INT_MAX; break;
|
|
|
|
|
case aco_opcode::v_lshlrev_b64:
|
|
|
|
|
case aco_opcode::v_lshlrev_b64_e64:
|
|
|
|
|
case aco_opcode::v_lshrrev_b64:
|
|
|
|
|
case aco_opcode::v_ashrrev_i64: constant_limit = 1; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
const Operand& op = info.operands[i].op;
|
|
|
|
|
if (!op.isLiteral() && !op.isOfType(RegType::sgpr))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
constant_limit--;
|
|
|
|
|
for (unsigned j = 0; j < i; j++) {
|
|
|
|
|
const Operand& other = info.operands[j].op;
|
|
|
|
|
if (op == other) {
|
|
|
|
|
constant_limit++;
|
|
|
|
|
break;
|
|
|
|
|
} else if (op.isLiteral() && other.isLiteral()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (constant_limit < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* apply extract. */
|
|
|
|
|
if (info.opcode == aco_opcode::s_pack_ll_b32_b16) {
|
|
|
|
|
if (info.operands[0].extract[0].size() < 2 || info.operands[1].extract[0].size() < 2)
|
|
|
|
|
return false;
|
|
|
|
|
if (info.operands[0].extract[0].offset() == 2 && info.operands[1].extract[0].offset() == 2) {
|
|
|
|
|
info.opcode = aco_opcode::s_pack_hh_b32_b16;
|
|
|
|
|
} else if (info.operands[0].extract[0].offset() == 0 &&
|
|
|
|
|
info.operands[1].extract[0].offset() == 2) {
|
|
|
|
|
info.opcode = aco_opcode::s_pack_lh_b32_b16;
|
|
|
|
|
} else if (info.operands[0].extract[0].offset() == 2 &&
|
|
|
|
|
info.operands[1].extract[0].offset() == 0) {
|
|
|
|
|
if (ctx.program->gfx_level < GFX11) /* TODO try shifting constant */
|
|
|
|
|
return false;
|
|
|
|
|
info.opcode = aco_opcode::s_pack_hl_b32_b16;
|
|
|
|
|
}
|
|
|
|
|
info.operands[0].extract[0] = SubdwordSel::dword;
|
|
|
|
|
info.operands[1].extract[0] = SubdwordSel::dword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
aco_type type = get_canonical_operand_type(info.opcode, i);
|
|
|
|
|
if (type.bit_size == 16 && type.num_components == 2) {
|
|
|
|
|
for (unsigned comp = 0; comp < 2; comp++) {
|
|
|
|
|
SubdwordSel sel = info.operands[i].extract[comp];
|
|
|
|
|
if (sel.size() < 2)
|
|
|
|
|
return false;
|
|
|
|
|
if (info.format != Format::VOP3P && sel.offset() != 2 * comp)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
SubdwordSel sel = info.operands[i].extract[0];
|
|
|
|
|
if (sel.size() == 4) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (info.operands[i].f16_to_f32 && sel.size() < 2) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (info.operands[i].f16_to_f32 && sel.size() == 2) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (sel.offset() == 0 && sel.size() >= bytes_used(ctx, info, i)) {
|
|
|
|
|
info.operands[i].extract[0] = SubdwordSel::dword;
|
|
|
|
|
} else if ((info.opcode == aco_opcode::v_cvt_f32_u32 ||
|
|
|
|
|
info.opcode == aco_opcode::v_cvt_f32_i32) &&
|
|
|
|
|
sel.size() == 1 && !sel.sign_extend()) {
|
|
|
|
|
switch (sel.offset()) {
|
|
|
|
|
case 0: info.opcode = aco_opcode::v_cvt_f32_ubyte0; break;
|
|
|
|
|
case 1: info.opcode = aco_opcode::v_cvt_f32_ubyte1; break;
|
|
|
|
|
case 2: info.opcode = aco_opcode::v_cvt_f32_ubyte2; break;
|
|
|
|
|
case 3: info.opcode = aco_opcode::v_cvt_f32_ubyte3; break;
|
|
|
|
|
default: UNREACHABLE("invalid SubdwordSel");
|
|
|
|
|
}
|
|
|
|
|
info.operands[i].extract[0] = SubdwordSel::dword;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (info.opcode == aco_opcode::v_mul_u32_u24 && ctx.program->gfx_level >= GFX10 &&
|
|
|
|
|
sel.size() == 2 && !sel.sign_extend() &&
|
|
|
|
|
!info.operands[!i].extract[0].sign_extend() &&
|
|
|
|
|
info.operands[!i].extract[0].size() >= 2 &&
|
|
|
|
|
(info.operands[!i].op.is16bit() || info.operands[!i].extract[0].size() == 2 ||
|
|
|
|
|
(info.operands[!i].op.isConstant() &&
|
|
|
|
|
info.operands[!i].op.constantValue() <= UINT16_MAX))) {
|
|
|
|
|
info.opcode = aco_opcode::v_mad_u32_u16;
|
|
|
|
|
info.format = Format::VOP3;
|
|
|
|
|
info.operands.push_back(alu_opt_op{});
|
|
|
|
|
info.operands[2].op = Operand::c32(0);
|
|
|
|
|
continue;
|
|
|
|
|
} else if (i < 2 && ctx.program->gfx_level >= GFX8 && ctx.program->gfx_level < GFX11 &&
|
|
|
|
|
(format_is(info.format, Format::VOPC) || format_is(info.format, Format::VOP2) ||
|
|
|
|
|
format_is(info.format, Format::VOP1))) {
|
|
|
|
|
info.format = format_combine(info.format, Format::SDWA);
|
|
|
|
|
continue;
|
|
|
|
|
} else if (sel.size() == 2 && can_use_opsel(ctx.program->gfx_level, info.opcode, i)) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (info.opcode == aco_opcode::s_cvt_f32_f16 && sel.size() == 2 && sel.offset() == 2) {
|
|
|
|
|
info.opcode = aco_opcode::s_cvt_hi_f32_f16;
|
|
|
|
|
info.operands[i].extract[0] = SubdwordSel::dword;
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert to v_fma_mix */
|
|
|
|
|
bool uses_f2f32 = false;
|
|
|
|
|
for (auto& op_info : info.operands)
|
|
|
|
|
uses_f2f32 |= op_info.f16_to_f32;
|
|
|
|
|
|
|
|
|
|
if (uses_f2f32 || info.f32_to_f16) {
|
|
|
|
|
if (ctx.program->gfx_level < GFX9)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* v_mad_mix* on GFX9 always flushes denormals for 16-bit inputs/outputs */
|
|
|
|
|
if (ctx.program->gfx_level == GFX9 && ctx.fp_mode.denorm16_64)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::v_add_f32:
|
|
|
|
|
info.operands.insert(info.operands.begin(), alu_opt_op{});
|
|
|
|
|
info.operands[0].op = Operand::c32(0x3f800000);
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mul_f32:
|
|
|
|
|
info.operands.push_back(alu_opt_op{});
|
|
|
|
|
info.operands[2].op = Operand::c32(0);
|
|
|
|
|
info.operands[2].neg[0] = true;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_fma_f32:
|
|
|
|
|
// TODO remove precise, not clear why unfusing fma would be valid
|
|
|
|
|
if (!ctx.program->dev.fused_mad_mix && info.defs[0].isPrecise())
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mad_f32:
|
|
|
|
|
if (ctx.program->dev.fused_mad_mix && info.defs[0].isPrecise())
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.opcode = info.f32_to_f16 ? aco_opcode::v_fma_mixlo_f16 : aco_opcode::v_fma_mix_f32;
|
|
|
|
|
info.format = Format::VOP3P;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove negate modifiers by converting to subtract */
|
|
|
|
|
aco_opcode sub = aco_opcode::num_opcodes;
|
|
|
|
|
aco_opcode subrev = aco_opcode::num_opcodes;
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::v_add_f32:
|
|
|
|
|
sub = aco_opcode::v_sub_f32;
|
|
|
|
|
subrev = aco_opcode::v_subrev_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_add_f16:
|
|
|
|
|
sub = aco_opcode::v_sub_f16;
|
|
|
|
|
subrev = aco_opcode::v_subrev_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::s_add_f32: sub = aco_opcode::s_sub_f32; break;
|
|
|
|
|
case aco_opcode::s_add_f16: sub = aco_opcode::s_sub_f16; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sub != aco_opcode::num_opcodes && (info.operands[0].neg[0] ^ info.operands[1].neg[0])) {
|
|
|
|
|
if (info.operands[1].neg[0]) {
|
|
|
|
|
info.opcode = sub;
|
|
|
|
|
} else if (subrev != aco_opcode::num_opcodes) {
|
|
|
|
|
info.opcode = subrev;
|
|
|
|
|
} else {
|
|
|
|
|
info.opcode = sub;
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.operands[0].neg[0] = false;
|
|
|
|
|
info.operands[1].neg[0] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert to DPP */
|
|
|
|
|
bool is_dpp = false;
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
if (info.operands[i].dpp16 || info.operands[i].dpp8) {
|
|
|
|
|
if (is_dpp || !info.try_swap_operands(0, i))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
is_dpp = true;
|
|
|
|
|
if (info.operands[0].dpp16)
|
|
|
|
|
info.format = format_combine(info.format, Format::DPP16);
|
|
|
|
|
else if (info.operands[0].dpp8)
|
|
|
|
|
info.format = format_combine(info.format, Format::DPP8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (is_dpp && info.operands.size() > 2 && !info.operands[1].op.isOfType(RegType::vgpr) &&
|
|
|
|
|
info.operands[2].op.isOfType(RegType::vgpr))
|
|
|
|
|
info.try_swap_operands(1, 2);
|
|
|
|
|
if (is_dpp && info.operands.size() > 1 && !info.operands[1].op.isOfType(RegType::vgpr))
|
|
|
|
|
return false; /* TODO: gfx11.5 */
|
|
|
|
|
|
|
|
|
|
/* dst SDWA */
|
|
|
|
|
if (info.insert != SubdwordSel::dword) {
|
|
|
|
|
if (info.insert.offset() == 0 && info.insert.size() >= info.defs[0].bytes()) {
|
|
|
|
|
info.insert = SubdwordSel::dword;
|
|
|
|
|
} else if (info.defs[0].bytes() != 4 ||
|
|
|
|
|
(!format_is(info.format, Format::VOP1) && !format_is(info.format, Format::VOP2))) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
info.format = format_combine(info.format, Format::SDWA);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* DPP and SDWA can't be used at the same time. */
|
|
|
|
|
if (is_dpp && format_is(info.format, Format::SDWA))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool is_dpp_or_sdwa = is_dpp || format_is(info.format, Format::SDWA);
|
|
|
|
|
|
|
|
|
|
bitarray8 neg = 0;
|
|
|
|
|
bitarray8 abs = 0;
|
|
|
|
|
bitarray8 opsel = 0;
|
|
|
|
|
bitarray8 vmask = 0;
|
|
|
|
|
bitarray8 smask = 0;
|
|
|
|
|
bitarray8 cmask = 0;
|
|
|
|
|
bitarray8 lmask = 0;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
aco_type type = get_canonical_operand_type(info.opcode, i);
|
|
|
|
|
bool can_use_mods = can_use_input_modifiers(ctx.program->gfx_level, info.opcode, i);
|
|
|
|
|
const auto& op_info = info.operands[i];
|
|
|
|
|
|
|
|
|
|
if (!format_is(info.format, Format::VOP3P) && type.num_components == 2 &&
|
|
|
|
|
(op_info.neg[0] != op_info.neg[1] || op_info.abs[0] != op_info.abs[1]))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned comp = 0; comp < type.num_components; comp++) {
|
|
|
|
|
if (!can_use_mods && (op_info.neg[comp] || op_info.abs[comp]))
|
|
|
|
|
return false;
|
|
|
|
|
abs[i] |= op_info.abs[comp];
|
|
|
|
|
neg[i] |= op_info.neg[comp];
|
|
|
|
|
}
|
|
|
|
|
opsel[i] = op_info.extract[0].offset();
|
|
|
|
|
vmask[i] = op_info.op.isOfType(RegType::vgpr);
|
|
|
|
|
smask[i] = op_info.op.isOfType(RegType::sgpr);
|
|
|
|
|
cmask[i] = op_info.op.isConstant();
|
|
|
|
|
lmask[i] = op_info.op.isLiteral();
|
|
|
|
|
|
|
|
|
|
/* lane masks must be sgpr */
|
|
|
|
|
if (type.bit_size == 1 && !smask[i])
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* DPP/SDWA doesn't allow 64bit opcodes. */
|
|
|
|
|
if (is_dpp_or_sdwa && info.operands[i].op.size() != 1 && type.bit_size != 1)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* DPP/SDWA doesn't allow 64bit opcodes. */
|
|
|
|
|
if (is_dpp_or_sdwa && !format_is(info.format, Format::VOPC) && info.defs[0].size() != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (format_is(info.format, Format::VOP1) || format_is(info.format, Format::VOP2) ||
|
|
|
|
|
format_is(info.format, Format::VOPC) || format_is(info.format, Format::VOP3)) {
|
|
|
|
|
bool needs_vop3 = false;
|
|
|
|
|
if (info.omod && format_is(info.format, Format::SDWA) && ctx.program->gfx_level < GFX9)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (info.omod && !format_is(info.format, Format::SDWA))
|
|
|
|
|
needs_vop3 = true;
|
|
|
|
|
|
|
|
|
|
if (info.clamp && format_is(info.format, Format::SDWA) &&
|
|
|
|
|
format_is(info.format, Format::VOPC) && ctx.program->gfx_level >= GFX9)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if ((info.clamp || (opsel & ~vmask)) && !format_is(info.format, Format::SDWA))
|
|
|
|
|
needs_vop3 = true;
|
|
|
|
|
|
|
|
|
|
if (!format_is(info.format, Format::SDWA) && !format_is(info.format, Format::DPP16) &&
|
|
|
|
|
(abs || neg))
|
|
|
|
|
needs_vop3 = true;
|
|
|
|
|
|
|
|
|
|
if (((cmask | smask) & 0x3) && format_is(info.format, Format::SDWA) &&
|
|
|
|
|
ctx.program->gfx_level == GFX8)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
aco_opcode mulk = aco_opcode::num_opcodes;
|
|
|
|
|
aco_opcode addk = aco_opcode::num_opcodes;
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::v_s_exp_f16:
|
|
|
|
|
case aco_opcode::v_s_log_f16:
|
|
|
|
|
case aco_opcode::v_s_rcp_f16:
|
|
|
|
|
case aco_opcode::v_s_rsq_f16:
|
|
|
|
|
case aco_opcode::v_s_sqrt_f16:
|
|
|
|
|
/* These can't use inline constants on GFX12 but can use literals. We don't bother since
|
|
|
|
|
* they should be constant folded anyway. */
|
|
|
|
|
if (cmask)
|
|
|
|
|
return false;
|
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
case aco_opcode::v_s_exp_f32:
|
|
|
|
|
case aco_opcode::v_s_log_f32:
|
|
|
|
|
case aco_opcode::v_s_rcp_f32:
|
|
|
|
|
case aco_opcode::v_s_rsq_f32:
|
|
|
|
|
case aco_opcode::v_s_sqrt_f32:
|
|
|
|
|
if (vmask)
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_writelane_b32:
|
|
|
|
|
case aco_opcode::v_writelane_b32_e64:
|
|
|
|
|
if ((vmask & 0x3) || (~vmask & 0x4))
|
|
|
|
|
return false;
|
|
|
|
|
if (is_dpp || format_is(info.format, Format::SDWA))
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_permlane16_b32:
|
|
|
|
|
case aco_opcode::v_permlanex16_b32:
|
|
|
|
|
case aco_opcode::v_permlane64_b32:
|
|
|
|
|
case aco_opcode::v_readfirstlane_b32:
|
|
|
|
|
case aco_opcode::v_readlane_b32:
|
|
|
|
|
case aco_opcode::v_readlane_b32_e64:
|
|
|
|
|
if ((~vmask & 0x1) || (vmask & 0x6))
|
|
|
|
|
return false;
|
|
|
|
|
if (is_dpp || format_is(info.format, Format::SDWA))
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mul_lo_u32:
|
|
|
|
|
case aco_opcode::v_mul_lo_i32:
|
|
|
|
|
case aco_opcode::v_mul_hi_u32:
|
|
|
|
|
case aco_opcode::v_mul_hi_i32:
|
|
|
|
|
if (is_dpp)
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_fma_f32:
|
|
|
|
|
if (ctx.program->gfx_level >= GFX10) {
|
|
|
|
|
mulk = aco_opcode::v_fmamk_f32;
|
|
|
|
|
addk = aco_opcode::v_fmaak_f32;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_fma_f16:
|
|
|
|
|
case aco_opcode::v_fma_legacy_f16:
|
|
|
|
|
if (ctx.program->gfx_level >= GFX10) {
|
|
|
|
|
mulk = aco_opcode::v_fmamk_f16;
|
|
|
|
|
addk = aco_opcode::v_fmaak_f16;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mad_f32:
|
|
|
|
|
mulk = aco_opcode::v_madmk_f32;
|
|
|
|
|
addk = aco_opcode::v_madak_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mad_f16:
|
|
|
|
|
case aco_opcode::v_mad_legacy_f16:
|
|
|
|
|
mulk = aco_opcode::v_madmk_f16;
|
|
|
|
|
addk = aco_opcode::v_madak_f16;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if ((smask[1] || cmask[1]) && !needs_vop3 && !format_is(info.format, Format::VOP3) &&
|
|
|
|
|
!format_is(info.format, Format::SDWA)) {
|
|
|
|
|
if (is_dpp || !vmask[0] || !info.try_swap_operands(0, 1))
|
|
|
|
|
needs_vop3 = true;
|
|
|
|
|
}
|
|
|
|
|
if (needs_vop3)
|
|
|
|
|
info.format = format_combine(info.format, Format::VOP3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addk != aco_opcode::num_opcodes && vmask && lmask && !needs_vop3 &&
|
|
|
|
|
(vmask[2] || lmask[2]) && (!opsel || ctx.program->gfx_level >= GFX11)) {
|
|
|
|
|
for (int i = 2; i >= 0; i--) {
|
|
|
|
|
if (lmask[i]) {
|
|
|
|
|
if (i == 0 || (i == 2 && !vmask[1]))
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
if (i != 2)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode = i == 2 ? addk : mulk;
|
|
|
|
|
info.format = Format::VOP2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nolit = format_is(info.format, Format::SDWA) || is_dpp ||
|
|
|
|
|
(format_is(info.format, Format::VOP3) && ctx.program->gfx_level < GFX10);
|
|
|
|
|
if (nolit && lmask)
|
|
|
|
|
return false;
|
|
|
|
|
if (is_dpp && format_is(info.format, Format::VOP3) && ctx.program->gfx_level < GFX11)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Fix lane mask src/dst to vcc if the format requires it. */
|
|
|
|
|
if (ctx.program->gfx_level < GFX11 && (is_dpp || format_is(info.format, Format::SDWA))) {
|
|
|
|
|
if (format_is(info.format, Format::VOP2)) {
|
|
|
|
|
if (info.operands.size() > 2)
|
|
|
|
|
info.operands[2].op.setPrecolored(vcc);
|
|
|
|
|
if (info.defs.size() > 1)
|
|
|
|
|
info.defs[1].setPrecolored(vcc);
|
|
|
|
|
}
|
|
|
|
|
if (format_is(info.format, Format::VOPC) && (is_dpp || ctx.program->gfx_level < GFX9) &&
|
|
|
|
|
!info.defs[0].isFixed())
|
|
|
|
|
info.defs[0].setPrecolored(vcc);
|
|
|
|
|
}
|
|
|
|
|
} else if (format_is(info.format, Format::VOP3P)) {
|
|
|
|
|
bool fmamix =
|
|
|
|
|
info.opcode == aco_opcode::v_fma_mix_f32 || info.opcode == aco_opcode::v_fma_mixlo_f16;
|
|
|
|
|
bool dot2_f32 =
|
|
|
|
|
info.opcode == aco_opcode::v_dot2_f32_f16 || info.opcode == aco_opcode::v_dot2_f32_bf16;
|
|
|
|
|
bool supports_dpp = (fmamix || dot2_f32) && ctx.program->gfx_level >= GFX11;
|
|
|
|
|
if ((abs && !fmamix) || (is_dpp && !supports_dpp) || info.omod)
|
|
|
|
|
return false;
|
|
|
|
|
if (lmask && (ctx.program->gfx_level < GFX10 || is_dpp))
|
|
|
|
|
return false;
|
|
|
|
|
} else if (is_salu) {
|
|
|
|
|
if (vmask)
|
|
|
|
|
return false;
|
|
|
|
|
if (info.opcode == aco_opcode::s_fmac_f32) {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (lmask[i]) {
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
std::swap(info.operands[i], info.operands[1]);
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
2025-03-27 21:20:39 +01:00
|
|
|
info.opcode = aco_opcode::s_fmamk_f32;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (info.opcode == aco_opcode::s_fmac_f32 && cmask[2]) {
|
|
|
|
|
info.operands[2].op = Operand::literal32(info.operands[2].op.constantValue());
|
|
|
|
|
lmask[2] = true;
|
|
|
|
|
info.opcode = aco_opcode::s_fmaak_f32;
|
|
|
|
|
}
|
|
|
|
|
} else if (info.opcode == aco_opcode::s_fmac_f16 && !smask[2]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Gather semantic information about an alu instruction and its operands from an ACO IR Instruction.
|
|
|
|
|
*
|
|
|
|
|
* Some callers expect that the alu_opt_info created by alu_opt_gather_info() or the instruction
|
|
|
|
|
* created by alu_opt_info_to_instr() does not have more uses of a temporary than the original
|
|
|
|
|
* instruction did.
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
alu_opt_gather_info(opt_ctx& ctx, Instruction* instr, alu_opt_info& info)
|
|
|
|
|
{
|
|
|
|
|
if (!instr->isVALU() && !instr->isSALU())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* There is nothing to be gained from handling WMMA/mqsad here. */
|
|
|
|
|
if (instr_info.classes[(int)instr->opcode] == instr_class::wmma ||
|
|
|
|
|
instr->opcode == aco_opcode::v_mqsad_u32_u8)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* TODO handle when this is used for output modifiers. */
|
|
|
|
|
if (instr->isVINTERP_INREG())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::s_addk_i32:
|
|
|
|
|
case aco_opcode::s_cmovk_i32:
|
|
|
|
|
case aco_opcode::s_mulk_i32:
|
|
|
|
|
case aco_opcode::v_dot2c_f32_f16:
|
|
|
|
|
case aco_opcode::v_dot4c_i32_i8:
|
|
|
|
|
case aco_opcode::v_fmac_f32:
|
|
|
|
|
case aco_opcode::v_fmac_f16:
|
|
|
|
|
case aco_opcode::v_fmac_legacy_f32:
|
|
|
|
|
case aco_opcode::v_mac_f32:
|
|
|
|
|
case aco_opcode::v_mac_f16:
|
|
|
|
|
case aco_opcode::v_mac_legacy_f32:
|
|
|
|
|
case aco_opcode::v_pk_fmac_f16: UNREACHABLE("Only created by RA."); return false;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = {};
|
|
|
|
|
|
|
|
|
|
info.opcode = instr->opcode;
|
|
|
|
|
info.pass_flags = instr->pass_flags;
|
|
|
|
|
|
|
|
|
|
if (instr->isSALU())
|
|
|
|
|
info.imm = instr->salu().imm;
|
|
|
|
|
|
|
|
|
|
bitarray8 opsel = 0;
|
|
|
|
|
if (instr->isVALU()) {
|
|
|
|
|
info.omod = instr->valu().omod;
|
|
|
|
|
info.clamp = instr->valu().clamp;
|
|
|
|
|
opsel = instr->valu().opsel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->opcode == aco_opcode::v_permlane16_b32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_permlanex16_b32) {
|
|
|
|
|
info.imm = opsel;
|
|
|
|
|
opsel = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->opcode == aco_opcode::v_fma_mix_f32 || instr->opcode == aco_opcode::v_fma_mixlo_f16) {
|
|
|
|
|
info.opcode = ctx.program->dev.fused_mad_mix ? aco_opcode::v_fma_f32 : aco_opcode::v_mad_f32;
|
|
|
|
|
info.f32_to_f16 = instr->opcode == aco_opcode::v_fma_mixlo_f16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->isSDWA())
|
|
|
|
|
info.insert = instr->sdwa().dst_sel;
|
|
|
|
|
else
|
|
|
|
|
info.insert = SubdwordSel::dword;
|
|
|
|
|
|
|
|
|
|
for (Definition& def : instr->definitions)
|
|
|
|
|
info.defs.push_back(def);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
alu_opt_op op_info = {};
|
|
|
|
|
op_info.op = instr->operands[i];
|
|
|
|
|
if (instr->opcode == aco_opcode::v_fma_mix_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_fma_mixlo_f16) {
|
|
|
|
|
op_info.neg[0] = instr->valu().neg[i];
|
|
|
|
|
op_info.abs[0] = instr->valu().abs[i];
|
|
|
|
|
if (instr->valu().opsel_hi[i]) {
|
|
|
|
|
op_info.f16_to_f32 = true;
|
|
|
|
|
if (instr->valu().opsel_lo[i])
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
}
|
|
|
|
|
} else if (instr->isVOP3P()) {
|
|
|
|
|
op_info.neg[0] = instr->valu().neg_lo[i];
|
|
|
|
|
op_info.neg[1] = instr->valu().neg_hi[i];
|
|
|
|
|
if (instr->valu().opsel_lo[i])
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
if (instr->valu().opsel_hi[i])
|
|
|
|
|
op_info.extract[1] = SubdwordSel::uword1;
|
|
|
|
|
} else if (instr->isVALU() && i < 3) {
|
|
|
|
|
op_info.neg[0] = instr->valu().neg[i];
|
|
|
|
|
op_info.neg[1] = instr->valu().neg[i];
|
|
|
|
|
op_info.abs[0] = instr->valu().abs[i];
|
|
|
|
|
op_info.abs[1] = instr->valu().abs[i];
|
|
|
|
|
if (opsel[i])
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
op_info.extract[1] = SubdwordSel::uword1;
|
|
|
|
|
|
|
|
|
|
if (i < 2 && instr->isSDWA())
|
|
|
|
|
op_info.extract[0] = instr->sdwa().sel[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.operands.push_back(op_info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->isDPP16()) {
|
|
|
|
|
info.operands[0].dpp16 = true;
|
|
|
|
|
info.operands[0].dpp_ctrl = instr->dpp16().dpp_ctrl;
|
|
|
|
|
info.operands[0].fi = instr->dpp16().fetch_inactive;
|
|
|
|
|
info.operands[0].bc = instr->dpp16().bound_ctrl;
|
|
|
|
|
assert(instr->dpp16().row_mask == 0xf && instr->dpp16().bank_mask == 0xf);
|
|
|
|
|
} else if (instr->isDPP8()) {
|
|
|
|
|
info.operands[0].dpp8 = true;
|
|
|
|
|
info.operands[0].dpp_ctrl = instr->dpp8().lane_sel;
|
|
|
|
|
info.operands[0].fi = instr->dpp8().fetch_inactive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (info.opcode) {
|
|
|
|
|
case aco_opcode::s_cvt_hi_f32_f16:
|
|
|
|
|
info.operands[0].extract[0] = SubdwordSel::uword1;
|
|
|
|
|
info.opcode = aco_opcode::s_cvt_f32_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::s_pack_lh_b32_b16:
|
|
|
|
|
case aco_opcode::s_pack_hl_b32_b16:
|
|
|
|
|
case aco_opcode::s_pack_hh_b32_b16:
|
|
|
|
|
if (info.opcode != aco_opcode::s_pack_lh_b32_b16)
|
|
|
|
|
info.operands[0].extract[0] = SubdwordSel::uword1;
|
|
|
|
|
if (info.opcode != aco_opcode::s_pack_hl_b32_b16)
|
|
|
|
|
info.operands[1].extract[0] = SubdwordSel::uword1;
|
|
|
|
|
info.opcode = aco_opcode::s_pack_ll_b32_b16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_sub_f32:
|
|
|
|
|
case aco_opcode::v_subrev_f32:
|
|
|
|
|
info.operands[info.opcode == aco_opcode::v_sub_f32].neg[0] ^= true;
|
|
|
|
|
info.opcode = aco_opcode::v_add_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_sub_f16:
|
|
|
|
|
case aco_opcode::v_subrev_f16:
|
|
|
|
|
info.operands[info.opcode == aco_opcode::v_sub_f16].neg[0] ^= true;
|
|
|
|
|
info.opcode = aco_opcode::v_add_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::s_sub_f32:
|
|
|
|
|
info.operands[1].neg[0] ^= true;
|
|
|
|
|
info.opcode = aco_opcode::s_add_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::s_sub_f16:
|
|
|
|
|
info.operands[1].neg[0] ^= true;
|
|
|
|
|
info.opcode = aco_opcode::s_add_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_dot4_i32_iu8:
|
|
|
|
|
case aco_opcode::v_dot8_i32_iu4:
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
info.operands[i].dot_sext = info.operands[i].neg[0];
|
|
|
|
|
info.operands[i].neg[0] = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_mad_f32:
|
|
|
|
|
if (ctx.fp_mode.denorm32)
|
|
|
|
|
break;
|
|
|
|
|
FALLTHROUGH;
|
|
|
|
|
case aco_opcode::v_fma_f32:
|
|
|
|
|
if (info.operands[2].op.constantEquals(0) && info.operands[2].neg[0]) {
|
|
|
|
|
info.operands.pop_back();
|
|
|
|
|
info.opcode = aco_opcode::v_mul_f32;
|
|
|
|
|
} else {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
uint32_t one = info.operands[i].f16_to_f32 ? 0x3c00 : 0x3f800000;
|
|
|
|
|
if (info.operands[i].op.constantEquals(one) && !info.operands[i].neg[0] &&
|
|
|
|
|
info.operands[i].extract[0] == SubdwordSel::dword) {
|
|
|
|
|
info.operands.erase(info.operands.begin() + i);
|
|
|
|
|
info.opcode = aco_opcode::v_add_f32;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_fmaak_f32:
|
|
|
|
|
case aco_opcode::v_fmamk_f32:
|
|
|
|
|
if (info.opcode == aco_opcode::v_fmamk_f32)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode = aco_opcode::v_fma_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_fmaak_f16:
|
|
|
|
|
case aco_opcode::v_fmamk_f16:
|
|
|
|
|
if (info.opcode == aco_opcode::v_fmamk_f16)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode = aco_opcode::v_fma_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_madak_f32:
|
|
|
|
|
case aco_opcode::v_madmk_f32:
|
|
|
|
|
if (info.opcode == aco_opcode::v_madmk_f32)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode = aco_opcode::v_mad_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_madak_f16:
|
|
|
|
|
case aco_opcode::v_madmk_f16:
|
|
|
|
|
if (info.opcode == aco_opcode::v_madmk_f16)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode =
|
|
|
|
|
ctx.program->gfx_level == GFX8 ? aco_opcode::v_mad_legacy_f16 : aco_opcode::v_mad_f16;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::s_fmaak_f32:
|
|
|
|
|
case aco_opcode::s_fmamk_f32:
|
|
|
|
|
if (info.opcode == aco_opcode::s_fmamk_f32)
|
|
|
|
|
std::swap(info.operands[1], info.operands[2]);
|
|
|
|
|
info.opcode = aco_opcode::s_fmac_f32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_subbrev_co_u32:
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
info.opcode = aco_opcode::v_subb_co_u32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_subrev_co_u32:
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
info.opcode = aco_opcode::v_sub_co_u32;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_subrev_co_u32_e64:
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
info.opcode = aco_opcode::v_sub_co_u32_e64;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_subrev_u32:
|
|
|
|
|
std::swap(info.operands[0], info.operands[1]);
|
|
|
|
|
info.opcode = aco_opcode::v_sub_u32;
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert an alu_opt_info to an ACO IR instruction.
|
|
|
|
|
* alu_opt_info_is_valid must have been called and returned true before this.
|
|
|
|
|
* If old_instr is large enough for the new instruction, it's reused.
|
|
|
|
|
* Otherwise a new instruction is allocated.
|
|
|
|
|
*/
|
|
|
|
|
Instruction*
|
|
|
|
|
alu_opt_info_to_instr(opt_ctx& ctx, alu_opt_info& info, Instruction* old_instr)
|
|
|
|
|
{
|
|
|
|
|
Instruction* instr;
|
|
|
|
|
if (old_instr && old_instr->definitions.size() >= info.defs.size() &&
|
|
|
|
|
old_instr->operands.size() >= info.operands.size() &&
|
|
|
|
|
get_instr_data_size(old_instr->format) >= get_instr_data_size(info.format)) {
|
|
|
|
|
instr = old_instr;
|
|
|
|
|
while (instr->operands.size() > info.operands.size())
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
while (instr->definitions.size() > info.defs.size())
|
|
|
|
|
instr->definitions.pop_back();
|
|
|
|
|
instr->opcode = info.opcode;
|
|
|
|
|
instr->format = info.format;
|
|
|
|
|
|
|
|
|
|
if (instr->isVALU()) {
|
|
|
|
|
instr->valu().abs = 0;
|
|
|
|
|
instr->valu().neg = 0;
|
|
|
|
|
instr->valu().opsel = 0;
|
|
|
|
|
instr->valu().opsel_hi = 0;
|
|
|
|
|
instr->valu().opsel_lo = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
instr = create_instruction(info.opcode, info.format, info.operands.size(), info.defs.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instr->pass_flags = info.pass_flags;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info.defs.size(); i++) {
|
|
|
|
|
instr->definitions[i] = info.defs[i];
|
|
|
|
|
ctx.info[info.defs[i].tempId()].parent_instr = instr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info.operands.size(); i++) {
|
|
|
|
|
instr->operands[i] = info.operands[i].op;
|
|
|
|
|
if (instr->opcode == aco_opcode::v_fma_mix_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_fma_mixlo_f16) {
|
|
|
|
|
instr->valu().neg[i] = info.operands[i].neg[0];
|
|
|
|
|
instr->valu().abs[i] = info.operands[i].abs[0];
|
|
|
|
|
instr->valu().opsel_hi[i] = info.operands[i].f16_to_f32;
|
|
|
|
|
instr->valu().opsel_lo[i] = info.operands[i].extract[0].offset();
|
|
|
|
|
} else if (instr->isVOP3P()) {
|
|
|
|
|
instr->valu().neg_lo[i] = info.operands[i].neg[0] || info.operands[i].dot_sext;
|
|
|
|
|
instr->valu().neg_hi[i] = info.operands[i].neg[1];
|
|
|
|
|
instr->valu().opsel_lo[i] = info.operands[i].extract[0].offset();
|
|
|
|
|
instr->valu().opsel_hi[i] = info.operands[i].extract[1].offset();
|
|
|
|
|
} else if (instr->isVALU()) {
|
|
|
|
|
instr->valu().neg[i] = info.operands[i].neg[0];
|
|
|
|
|
instr->valu().abs[i] = info.operands[i].abs[0];
|
|
|
|
|
if (instr->isSDWA() && i < 2) {
|
|
|
|
|
SubdwordSel sel = info.operands[i].extract[0];
|
|
|
|
|
unsigned size = MIN2(sel.size(), info.operands[i].op.bytes());
|
|
|
|
|
instr->sdwa().sel[i] = SubdwordSel(size, sel.offset(), sel.sign_extend());
|
|
|
|
|
} else if (info.operands[i].extract[0].offset()) {
|
|
|
|
|
instr->valu().opsel[i] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->isVALU()) {
|
|
|
|
|
instr->valu().omod = info.omod;
|
|
|
|
|
instr->valu().clamp = info.clamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->isDPP16()) {
|
|
|
|
|
instr->dpp16().dpp_ctrl = info.operands[0].dpp_ctrl;
|
|
|
|
|
instr->dpp16().fetch_inactive = info.operands[0].fi;
|
|
|
|
|
instr->dpp16().bound_ctrl = info.operands[0].bc;
|
|
|
|
|
instr->dpp16().row_mask = 0xf;
|
|
|
|
|
instr->dpp16().bank_mask = 0xf;
|
|
|
|
|
} else if (instr->isDPP8()) {
|
|
|
|
|
instr->dpp8().lane_sel = info.operands[0].dpp_ctrl;
|
|
|
|
|
instr->dpp8().fetch_inactive = info.operands[0].fi;
|
|
|
|
|
} else if (instr->isSDWA()) {
|
|
|
|
|
instr->sdwa().dst_sel = info.insert;
|
|
|
|
|
if (!instr->isVOPC() && instr->definitions[0].bytes() != 4) {
|
|
|
|
|
instr->sdwa().dst_sel = SubdwordSel(instr->definitions[0].bytes(), 0, false);
|
|
|
|
|
assert(instr->sdwa().dst_sel == info.insert || info.insert == SubdwordSel::dword);
|
|
|
|
|
}
|
|
|
|
|
} else if (instr->opcode == aco_opcode::v_permlane16_b32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_permlanex16_b32) {
|
|
|
|
|
instr->valu().opsel = info.imm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instr->isSALU())
|
|
|
|
|
instr->salu().imm = info.imm;
|
|
|
|
|
|
|
|
|
|
return instr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 17:49:40 +01:00
|
|
|
bool
|
|
|
|
|
can_use_VOP3(opt_ctx& ctx, const aco_ptr<Instruction>& instr)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2019-11-22 15:00:04 +00:00
|
|
|
if (instr->isVOP3())
|
|
|
|
|
return true;
|
|
|
|
|
|
2024-07-24 18:10:12 +02:00
|
|
|
if (instr->isVOP3P() || instr->isVINTERP_INREG())
|
2020-09-04 12:35:54 +01:00
|
|
|
return false;
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (instr->operands.size() && instr->operands[0].isLiteral() && ctx.program->gfx_level < GFX10)
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
2023-05-16 17:55:57 +02:00
|
|
|
if (instr->isSDWA())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (instr->isDPP() && ctx.program->gfx_level < GFX11)
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return instr->opcode != aco_opcode::v_madmk_f32 && instr->opcode != aco_opcode::v_madak_f32 &&
|
2019-11-07 18:02:33 +01:00
|
|
|
instr->opcode != aco_opcode::v_madmk_f16 && instr->opcode != aco_opcode::v_madak_f16 &&
|
2019-11-22 15:00:04 +00:00
|
|
|
instr->opcode != aco_opcode::v_fmamk_f32 && instr->opcode != aco_opcode::v_fmaak_f32 &&
|
|
|
|
|
instr->opcode != aco_opcode::v_fmamk_f16 && instr->opcode != aco_opcode::v_fmaak_f16 &&
|
2024-01-18 22:57:45 +01:00
|
|
|
instr->opcode != aco_opcode::v_permlane64_b32 &&
|
2019-11-07 18:02:33 +01:00
|
|
|
instr->opcode != aco_opcode::v_readlane_b32 &&
|
|
|
|
|
instr->opcode != aco_opcode::v_writelane_b32 &&
|
|
|
|
|
instr->opcode != aco_opcode::v_readfirstlane_b32;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-31 11:01:08 +00:00
|
|
|
bool
|
|
|
|
|
pseudo_propagate_temp(opt_ctx& ctx, aco_ptr<Instruction>& instr, Temp temp, unsigned index)
|
|
|
|
|
{
|
|
|
|
|
if (instr->definitions.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const bool vgpr =
|
|
|
|
|
instr->opcode == aco_opcode::p_as_uniform ||
|
|
|
|
|
std::all_of(instr->definitions.begin(), instr->definitions.end(),
|
|
|
|
|
[](const Definition& def) { return def.regClass().type() == RegType::vgpr; });
|
|
|
|
|
|
|
|
|
|
/* don't propagate VGPRs into SGPR instructions */
|
|
|
|
|
if (temp.type() == RegType::vgpr && !vgpr)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool can_accept_sgpr =
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.program->gfx_level >= GFX9 ||
|
2020-12-31 11:01:08 +00:00
|
|
|
std::none_of(instr->definitions.begin(), instr->definitions.end(),
|
|
|
|
|
[](const Definition& def) { return def.regClass().is_subdword(); });
|
|
|
|
|
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::p_phi:
|
|
|
|
|
case aco_opcode::p_linear_phi:
|
|
|
|
|
case aco_opcode::p_parallelcopy:
|
|
|
|
|
case aco_opcode::p_create_vector:
|
2024-02-19 17:00:19 +00:00
|
|
|
case aco_opcode::p_start_linear_vgpr:
|
2020-12-31 11:01:08 +00:00
|
|
|
if (temp.bytes() != instr->operands[index].bytes())
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::p_extract_vector:
|
2021-10-05 13:09:02 +01:00
|
|
|
case aco_opcode::p_extract:
|
2020-12-31 11:01:08 +00:00
|
|
|
if (temp.type() == RegType::sgpr && !can_accept_sgpr)
|
|
|
|
|
return false;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::p_split_vector: {
|
|
|
|
|
if (temp.type() == RegType::sgpr && !can_accept_sgpr)
|
|
|
|
|
return false;
|
|
|
|
|
/* don't increase the vector size */
|
|
|
|
|
if (temp.bytes() > instr->operands[index].bytes())
|
|
|
|
|
return false;
|
|
|
|
|
/* We can decrease the vector size as smaller temporaries are only
|
|
|
|
|
* propagated by p_as_uniform instructions.
|
|
|
|
|
* If this propagation leads to invalid IR or hits the assertion below,
|
|
|
|
|
* it means that some undefined bytes within a dword are begin accessed
|
|
|
|
|
* and a bug in instruction_selection is likely. */
|
|
|
|
|
int decrease = instr->operands[index].bytes() - temp.bytes();
|
|
|
|
|
while (decrease > 0) {
|
|
|
|
|
decrease -= instr->definitions.back().bytes();
|
|
|
|
|
instr->definitions.pop_back();
|
|
|
|
|
}
|
|
|
|
|
assert(decrease == 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::p_as_uniform:
|
|
|
|
|
if (temp.regClass() == instr->definitions[0].regClass())
|
|
|
|
|
instr->opcode = aco_opcode::p_parallelcopy;
|
|
|
|
|
break;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instr->operands[index].setTemp(temp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* only covers special cases */
|
2020-01-16 16:54:35 +01:00
|
|
|
bool
|
2024-10-21 18:35:22 +02:00
|
|
|
pseudo_can_accept_constant(const aco_ptr<Instruction>& instr, unsigned operand)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-05-03 18:58:36 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
|
switch (instr->opcode) {
|
2019-09-17 13:22:17 +02:00
|
|
|
case aco_opcode::p_extract_vector:
|
|
|
|
|
case aco_opcode::p_split_vector:
|
2020-08-12 14:35:15 +01:00
|
|
|
case aco_opcode::p_extract:
|
|
|
|
|
case aco_opcode::p_insert: return operand != 0;
|
2023-08-15 21:01:49 +01:00
|
|
|
case aco_opcode::p_bpermute_readlane:
|
|
|
|
|
case aco_opcode::p_bpermute_shared_vgpr:
|
|
|
|
|
case aco_opcode::p_bpermute_permlane:
|
aco/gfx10: optimize subgroupRotate(x, 32) and subgroupShuffleXor(x, 32)
We don't have v_permlane64_b32 yet, but we can still optimize it using
shared vgprs. Using the DPP16 row mask, we can even avoid writing exec.
With v0 input/output and v24/v25 as shared vgprs, this results in:
v_mov_b32_dpp v24, v0 quad_perm:[0,1,2,3] row_mask:0x3 bank_mask:0xf
v_mov_b32_dpp v25, v0 quad_perm:[0,1,2,3] row_mask:0xc bank_mask:0xf
v_mov_b32_dpp v0, v24 quad_perm:[0,1,2,3] row_mask:0xc bank_mask:0xf
v_mov_b32_dpp v0, v25 quad_perm:[0,1,2,3] row_mask:0x3 bank_mask:0xf
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36390>
2025-07-26 13:54:17 +02:00
|
|
|
case aco_opcode::p_permlane64_shared_vgpr:
|
2022-11-16 15:18:54 +01:00
|
|
|
case aco_opcode::p_interp_gfx11:
|
2024-10-21 18:35:22 +02:00
|
|
|
case aco_opcode::p_dual_src_export_gfx11: return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
default: return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 14:50:41 +00:00
|
|
|
/* check constant bus and literal limitations */
|
|
|
|
|
bool
|
|
|
|
|
check_vop3_operands(opt_ctx& ctx, unsigned num_operands, Operand* operands)
|
|
|
|
|
{
|
2022-05-12 02:50:17 -04:00
|
|
|
int limit = ctx.program->gfx_level >= GFX10 ? 2 : 1;
|
2019-11-20 16:42:17 +00:00
|
|
|
Operand literal32(s1);
|
|
|
|
|
Operand literal64(s2);
|
2019-11-22 14:50:41 +00:00
|
|
|
unsigned num_sgprs = 0;
|
|
|
|
|
unsigned sgpr[] = {0, 0};
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_operands; i++) {
|
|
|
|
|
Operand op = operands[i];
|
|
|
|
|
|
|
|
|
|
if (op.hasRegClass() && op.regClass().type() == RegType::sgpr) {
|
|
|
|
|
/* two reads of the same SGPR count as 1 to the limit */
|
|
|
|
|
if (op.tempId() != sgpr[0] && op.tempId() != sgpr[1]) {
|
|
|
|
|
if (num_sgprs < 2)
|
|
|
|
|
sgpr[num_sgprs++] = op.tempId();
|
|
|
|
|
limit--;
|
|
|
|
|
if (limit < 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (op.isLiteral()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.program->gfx_level < GFX10)
|
2019-11-20 16:42:17 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!literal32.isUndefined() && literal32.constantValue() != op.constantValue())
|
|
|
|
|
return false;
|
|
|
|
|
if (!literal64.isUndefined() && literal64.constantValue() != op.constantValue())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Any number of 32-bit literals counts as only 1 to the limit. Same
|
|
|
|
|
* (but separately) for 64-bit literals. */
|
|
|
|
|
if (op.size() == 1 && literal32.isUndefined()) {
|
|
|
|
|
limit--;
|
|
|
|
|
literal32 = op;
|
|
|
|
|
} else if (op.size() == 2 && literal64.isUndefined()) {
|
|
|
|
|
limit--;
|
|
|
|
|
literal64 = op;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (limit < 0)
|
|
|
|
|
return false;
|
2019-11-22 14:50:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 17:00:55 +01:00
|
|
|
bool
|
|
|
|
|
parse_base_offset(opt_ctx& ctx, Instruction* instr, unsigned op_index, Temp* base, uint32_t* offset,
|
|
|
|
|
bool prevent_overflow)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
Operand op = instr->operands[op_index];
|
|
|
|
|
|
|
|
|
|
if (!op.isTemp())
|
|
|
|
|
return false;
|
|
|
|
|
Temp tmp = op.getTemp();
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* add_instr = ctx.info[tmp.id()].parent_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (add_instr->definitions[0].getTemp() != tmp)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-05-19 15:34:04 +01:00
|
|
|
unsigned mask = 0x3;
|
|
|
|
|
bool is_sub = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
switch (add_instr->opcode) {
|
|
|
|
|
case aco_opcode::v_add_u32:
|
|
|
|
|
case aco_opcode::v_add_co_u32:
|
2020-02-21 12:02:06 +00:00
|
|
|
case aco_opcode::v_add_co_u32_e64:
|
2019-09-17 13:22:17 +02:00
|
|
|
case aco_opcode::s_add_i32:
|
|
|
|
|
case aco_opcode::s_add_u32: break;
|
2022-05-19 15:34:04 +01:00
|
|
|
case aco_opcode::v_sub_u32:
|
|
|
|
|
case aco_opcode::v_sub_i32:
|
|
|
|
|
case aco_opcode::v_sub_co_u32:
|
|
|
|
|
case aco_opcode::v_sub_co_u32_e64:
|
|
|
|
|
case aco_opcode::s_sub_u32:
|
|
|
|
|
case aco_opcode::s_sub_i32:
|
|
|
|
|
mask = 0x2;
|
|
|
|
|
is_sub = true;
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::v_subrev_u32:
|
|
|
|
|
case aco_opcode::v_subrev_co_u32:
|
|
|
|
|
case aco_opcode::v_subrev_co_u32_e64:
|
|
|
|
|
mask = 0x1;
|
|
|
|
|
is_sub = true;
|
|
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
default: return false;
|
|
|
|
|
}
|
2019-10-15 17:25:57 +01:00
|
|
|
if (prevent_overflow && !add_instr->definitions[0].isNUW())
|
|
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-10-29 13:59:59 +00:00
|
|
|
if (add_instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-05-19 15:34:04 +01:00
|
|
|
u_foreach_bit (i, mask) {
|
2019-09-17 13:22:17 +02:00
|
|
|
if (add_instr->operands[i].isConstant()) {
|
2022-05-19 15:34:04 +01:00
|
|
|
*offset = add_instr->operands[i].constantValue() * (uint32_t)(is_sub ? -1 : 1);
|
2019-09-17 13:22:17 +02:00
|
|
|
} else if (add_instr->operands[i].isTemp() &&
|
2020-05-15 16:28:03 +01:00
|
|
|
ctx.info[add_instr->operands[i].tempId()].is_constant_or_literal(32)) {
|
2022-05-19 15:34:04 +01:00
|
|
|
*offset = ctx.info[add_instr->operands[i].tempId()].val * (uint32_t)(is_sub ? -1 : 1);
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!add_instr->operands[!i].isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
uint32_t offset2 = 0;
|
2019-10-15 17:00:55 +01:00
|
|
|
if (parse_base_offset(ctx, add_instr, !i, base, &offset2, prevent_overflow)) {
|
2019-09-17 13:22:17 +02:00
|
|
|
*offset += offset2;
|
|
|
|
|
} else {
|
|
|
|
|
*base = add_instr->operands[!i].getTemp();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
void
|
2025-03-11 14:11:45 +00:00
|
|
|
skip_smem_offset_align(opt_ctx& ctx, SMEM_instruction* smem, uint32_t align)
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
{
|
|
|
|
|
bool soe = smem->operands.size() >= (!smem->definitions.empty() ? 3 : 4);
|
|
|
|
|
if (soe && !smem->operands[1].isConstant())
|
|
|
|
|
return;
|
|
|
|
|
/* We don't need to check the constant offset because the address seems to be calculated with
|
|
|
|
|
* (offset&-4 + const_offset&-4), not (offset+const_offset)&-4.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
Operand& op = smem->operands[soe ? smem->operands.size() - 1 : 1];
|
2024-07-30 11:31:15 +02:00
|
|
|
if (!op.isTemp())
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
return;
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* bitwise_instr = ctx.info[op.tempId()].parent_instr;
|
2024-07-30 11:31:15 +02:00
|
|
|
if (bitwise_instr->opcode != aco_opcode::s_and_b32 ||
|
|
|
|
|
bitwise_instr->definitions[0].getTemp() != op.getTemp())
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-03-11 14:11:45 +00:00
|
|
|
uint32_t mask = ~(align - 1u);
|
|
|
|
|
if (bitwise_instr->operands[0].constantEquals(mask) &&
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
bitwise_instr->operands[1].isOfType(op.regClass().type()))
|
|
|
|
|
op.setTemp(bitwise_instr->operands[1].getTemp());
|
2025-03-11 14:11:45 +00:00
|
|
|
else if (bitwise_instr->operands[1].constantEquals(mask) &&
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
bitwise_instr->operands[0].isOfType(op.regClass().type()))
|
|
|
|
|
op.setTemp(bitwise_instr->operands[0].getTemp());
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-14 19:51:50 +00:00
|
|
|
void
|
|
|
|
|
smem_combine(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2025-03-11 14:11:45 +00:00
|
|
|
uint32_t align = 4;
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::s_load_sbyte:
|
|
|
|
|
case aco_opcode::s_load_ubyte:
|
|
|
|
|
case aco_opcode::s_buffer_load_sbyte:
|
|
|
|
|
case aco_opcode::s_buffer_load_ubyte: align = 1; break;
|
|
|
|
|
case aco_opcode::s_load_sshort:
|
|
|
|
|
case aco_opcode::s_load_ushort:
|
|
|
|
|
case aco_opcode::s_buffer_load_sshort:
|
|
|
|
|
case aco_opcode::s_buffer_load_ushort: align = 2; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-14 19:51:50 +00:00
|
|
|
/* skip &-4 before offset additions: load((a + 16) & -4, 0) */
|
2025-03-11 14:11:45 +00:00
|
|
|
if (!instr->operands.empty() && align > 1)
|
|
|
|
|
skip_smem_offset_align(ctx, &instr->smem(), align);
|
2021-12-14 19:51:50 +00:00
|
|
|
|
|
|
|
|
/* propagate constants and combine additions */
|
|
|
|
|
if (!instr->operands.empty() && instr->operands[1].isTemp()) {
|
|
|
|
|
SMEM_instruction& smem = instr->smem();
|
|
|
|
|
ssa_info info = ctx.info[instr->operands[1].tempId()];
|
|
|
|
|
|
|
|
|
|
Temp base;
|
|
|
|
|
uint32_t offset;
|
aco: increase max_const_offset_plus_one for SMEM load_global
fossil-db (gfx1201):
Totals from 1115 (1.40% of 79377) affected shaders:
Instrs: 1473805 -> 1467571 (-0.42%); split: -0.43%, +0.01%
CodeSize: 7852972 -> 7819656 (-0.42%); split: -0.44%, +0.02%
SpillSGPRs: 1632 -> 1460 (-10.54%); split: -11.27%, +0.74%
Latency: 11975762 -> 11971915 (-0.03%); split: -0.05%, +0.02%
InvThroughput: 2496961 -> 2496448 (-0.02%); split: -0.03%, +0.01%
VClause: 25213 -> 25218 (+0.02%); split: -0.00%, +0.02%
SClause: 28822 -> 28565 (-0.89%); split: -1.41%, +0.52%
Copies: 106377 -> 105715 (-0.62%); split: -1.23%, +0.61%
Branches: 27497 -> 27473 (-0.09%)
PreSGPRs: 52071 -> 51310 (-1.46%)
VALU: 871051 -> 870694 (-0.04%); split: -0.04%, +0.00%
SALU: 186090 -> 181811 (-2.30%); split: -2.32%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34730>
2025-04-23 16:41:53 +01:00
|
|
|
if (info.is_constant_or_literal(32) && info.val <= ctx.program->dev.smem_offset_max) {
|
2021-12-14 19:51:50 +00:00
|
|
|
instr->operands[1] = Operand::c32(info.val);
|
2023-04-18 14:50:18 +01:00
|
|
|
} else if (parse_base_offset(ctx, instr.get(), 1, &base, &offset, true) &&
|
aco: increase max_const_offset_plus_one for SMEM load_global
fossil-db (gfx1201):
Totals from 1115 (1.40% of 79377) affected shaders:
Instrs: 1473805 -> 1467571 (-0.42%); split: -0.43%, +0.01%
CodeSize: 7852972 -> 7819656 (-0.42%); split: -0.44%, +0.02%
SpillSGPRs: 1632 -> 1460 (-10.54%); split: -11.27%, +0.74%
Latency: 11975762 -> 11971915 (-0.03%); split: -0.05%, +0.02%
InvThroughput: 2496961 -> 2496448 (-0.02%); split: -0.03%, +0.01%
VClause: 25213 -> 25218 (+0.02%); split: -0.00%, +0.02%
SClause: 28822 -> 28565 (-0.89%); split: -1.41%, +0.52%
Copies: 106377 -> 105715 (-0.62%); split: -1.23%, +0.61%
Branches: 27497 -> 27473 (-0.09%)
PreSGPRs: 52071 -> 51310 (-1.46%)
VALU: 871051 -> 870694 (-0.04%); split: -0.04%, +0.00%
SALU: 186090 -> 181811 (-2.30%); split: -2.32%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34730>
2025-04-23 16:41:53 +01:00
|
|
|
base.regClass() == s1 && offset <= ctx.program->dev.smem_offset_max &&
|
2025-03-11 14:11:45 +00:00
|
|
|
ctx.program->gfx_level >= GFX9 && offset % align == 0) {
|
2021-12-14 19:51:50 +00:00
|
|
|
bool soe = smem.operands.size() >= (!smem.definitions.empty() ? 3 : 4);
|
|
|
|
|
if (soe) {
|
|
|
|
|
if (ctx.info[smem.operands.back().tempId()].is_constant_or_literal(32) &&
|
|
|
|
|
ctx.info[smem.operands.back().tempId()].val == 0) {
|
|
|
|
|
smem.operands[1] = Operand::c32(offset);
|
|
|
|
|
smem.operands.back() = Operand(base);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-03-25 15:55:27 +01:00
|
|
|
Instruction* new_instr = create_instruction(
|
2021-12-14 19:51:50 +00:00
|
|
|
smem.opcode, Format::SMEM, smem.operands.size() + 1, smem.definitions.size());
|
|
|
|
|
new_instr->operands[0] = smem.operands[0];
|
|
|
|
|
new_instr->operands[1] = Operand::c32(offset);
|
|
|
|
|
if (smem.definitions.empty())
|
|
|
|
|
new_instr->operands[2] = smem.operands[2];
|
|
|
|
|
new_instr->operands.back() = Operand(base);
|
|
|
|
|
if (!smem.definitions.empty())
|
|
|
|
|
new_instr->definitions[0] = smem.definitions[0];
|
2024-03-25 12:05:50 +01:00
|
|
|
new_instr->smem().sync = smem.sync;
|
2024-05-14 18:34:01 +01:00
|
|
|
new_instr->smem().cache = smem.cache;
|
2021-12-14 19:51:50 +00:00
|
|
|
instr.reset(new_instr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* skip &-4 after offset additions: load(a & -4, 16) */
|
2025-03-11 14:11:45 +00:00
|
|
|
if (!instr->operands.empty() && align > 1)
|
|
|
|
|
skip_smem_offset_align(ctx, &instr->smem(), align);
|
2021-12-14 19:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-15 16:28:03 +01:00
|
|
|
Operand
|
|
|
|
|
get_constant_op(opt_ctx& ctx, ssa_info info, uint32_t bits)
|
2019-11-14 08:09:32 +01:00
|
|
|
{
|
2020-12-03 15:18:30 +00:00
|
|
|
if (bits == 64)
|
2021-07-13 11:22:46 +02:00
|
|
|
return Operand::c32_or_c64(info.val, true);
|
2022-05-12 02:50:17 -04:00
|
|
|
return Operand::get_const(ctx.program->gfx_level, info.val, bits / 8u);
|
2019-11-14 08:09:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-28 12:04:48 +00:00
|
|
|
bool
|
|
|
|
|
fixed_to_exec(Operand op)
|
|
|
|
|
{
|
|
|
|
|
return op.isFixed() && op.physReg() == exec;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 17:58:36 +02:00
|
|
|
SubdwordSel
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
parse_extract(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->opcode == aco_opcode::p_extract) {
|
2021-08-30 17:58:36 +02:00
|
|
|
unsigned size = instr->operands[2].constantValue() / 8;
|
|
|
|
|
unsigned offset = instr->operands[1].constantValue() * size;
|
|
|
|
|
bool sext = instr->operands[3].constantEquals(1);
|
|
|
|
|
return SubdwordSel(size, offset, sext);
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::p_insert && instr->operands[1].constantEquals(0)) {
|
2021-08-30 17:58:36 +02:00
|
|
|
return instr->operands[2].constantEquals(8) ? SubdwordSel::ubyte : SubdwordSel::uword;
|
2021-10-04 11:13:08 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::p_extract_vector) {
|
|
|
|
|
unsigned size = instr->definitions[0].bytes();
|
|
|
|
|
unsigned offset = instr->operands[1].constantValue() * size;
|
|
|
|
|
if (size <= 2)
|
|
|
|
|
return SubdwordSel(size, offset, false);
|
aco/optimizer: apply extract from subdword p_split_vector
Totals from 1345 (1.00% of 134572) affected shaders: (GFX10.3)
VGPRs: 76752 -> 76744 (-0.01%); split: -0.02%, +0.01%
SpillSGPRs: 1459 -> 1460 (+0.07%)
SpillVGPRs: 1776 -> 1784 (+0.45%); split: -0.39%, +0.84%
CodeSize: 13310964 -> 13309420 (-0.01%); split: -0.06%, +0.05%
Scratch: 178176 -> 179200 (+0.57%)
Instrs: 2516874 -> 2516860 (-0.00%); split: -0.05%, +0.05%
Latency: 23228506 -> 23230338 (+0.01%); split: -0.14%, +0.15%
InvThroughput: 6002384 -> 6000158 (-0.04%); split: -0.24%, +0.21%
VClause: 41115 -> 41117 (+0.00%); split: -0.28%, +0.29%
SClause: 104639 -> 104664 (+0.02%); split: -0.07%, +0.09%
Copies: 185121 -> 184862 (-0.14%); split: -0.69%, +0.55%
Branches: 100740 -> 100735 (-0.00%); split: -0.01%, +0.00%
PreVGPRs: 70119 -> 69968 (-0.22%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13576>
2021-10-25 16:44:42 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::p_split_vector) {
|
|
|
|
|
assert(instr->operands[0].bytes() == 4 && instr->definitions[1].bytes() == 2);
|
|
|
|
|
return SubdwordSel(2, 2, false);
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
2021-10-04 11:13:08 +01:00
|
|
|
|
|
|
|
|
return SubdwordSel();
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 17:58:36 +02:00
|
|
|
SubdwordSel
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
parse_insert(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->opcode == aco_opcode::p_extract && instr->operands[3].constantEquals(0) &&
|
|
|
|
|
instr->operands[1].constantEquals(0)) {
|
2021-08-30 17:58:36 +02:00
|
|
|
return instr->operands[2].constantEquals(8) ? SubdwordSel::ubyte : SubdwordSel::uword;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::p_insert) {
|
2021-08-30 17:58:36 +02:00
|
|
|
unsigned size = instr->operands[2].constantValue() / 8;
|
|
|
|
|
unsigned offset = instr->operands[1].constantValue() * size;
|
|
|
|
|
return SubdwordSel(size, offset, false);
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
} else {
|
2021-08-30 17:58:36 +02:00
|
|
|
return SubdwordSel();
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2024-11-23 16:42:42 +01:00
|
|
|
remove_operand_extract(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
{
|
2024-11-23 16:42:42 +01:00
|
|
|
/* We checked these earlier in alu_propagate_temp_const */
|
|
|
|
|
if (instr->isSALU() || instr->isVALU())
|
|
|
|
|
return;
|
|
|
|
|
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
Operand op = instr->operands[i];
|
|
|
|
|
if (!op.isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
ssa_info& info = ctx.info[op.tempId()];
|
2024-11-23 16:42:42 +01:00
|
|
|
info.label &= ~label_extract;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 10:35:03 +00:00
|
|
|
bool
|
|
|
|
|
does_fp_op_flush_denorms(opt_ctx& ctx, aco_opcode op)
|
2020-06-17 15:02:30 +01:00
|
|
|
{
|
2023-02-07 21:54:06 +01:00
|
|
|
switch (op) {
|
|
|
|
|
case aco_opcode::v_min_f32:
|
|
|
|
|
case aco_opcode::v_max_f32:
|
|
|
|
|
case aco_opcode::v_med3_f32:
|
|
|
|
|
case aco_opcode::v_min3_f32:
|
|
|
|
|
case aco_opcode::v_max3_f32:
|
|
|
|
|
case aco_opcode::v_min_f16:
|
|
|
|
|
case aco_opcode::v_max_f16: return ctx.program->gfx_level > GFX8;
|
|
|
|
|
case aco_opcode::v_cndmask_b32:
|
|
|
|
|
case aco_opcode::v_cndmask_b16:
|
|
|
|
|
case aco_opcode::v_mov_b32:
|
|
|
|
|
case aco_opcode::v_mov_b16: return false;
|
|
|
|
|
default: return true;
|
2021-02-05 10:35:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 18:01:45 +02:00
|
|
|
bool
|
2025-07-07 17:57:20 +01:00
|
|
|
can_eliminate_and_exec(opt_ctx& ctx, Temp tmp, unsigned pass_flags, bool allow_cselect = false)
|
2022-03-30 18:01:45 +02:00
|
|
|
{
|
2024-07-30 11:31:15 +02:00
|
|
|
Instruction* instr = ctx.info[tmp.id()].parent_instr;
|
|
|
|
|
/* Remove superfluous s_and when the VOPC instruction uses the same exec and thus
|
|
|
|
|
* already produces the same result */
|
|
|
|
|
if (instr->isVOPC())
|
|
|
|
|
return instr->pass_flags == pass_flags;
|
2024-07-23 14:47:15 +02:00
|
|
|
|
2025-07-07 17:57:20 +01:00
|
|
|
if (allow_cselect && instr->pass_flags == pass_flags &&
|
|
|
|
|
(instr->opcode == aco_opcode::s_cselect_b32 || instr->opcode == aco_opcode::s_cselect_b64)) {
|
|
|
|
|
return (instr->operands[0].constantEquals(0) && instr->operands[1].constantEquals(-1)) ||
|
|
|
|
|
(instr->operands[1].constantEquals(0) && instr->operands[0].constantEquals(-1));
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (instr->operands.size() != 2 || instr->pass_flags != pass_flags)
|
|
|
|
|
return false;
|
|
|
|
|
if (!(instr->operands[0].isTemp() && instr->operands[1].isTemp()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::s_and_b32:
|
|
|
|
|
case aco_opcode::s_and_b64:
|
|
|
|
|
return can_eliminate_and_exec(ctx, instr->operands[0].getTemp(), pass_flags) ||
|
|
|
|
|
can_eliminate_and_exec(ctx, instr->operands[1].getTemp(), pass_flags);
|
|
|
|
|
case aco_opcode::s_or_b32:
|
|
|
|
|
case aco_opcode::s_or_b64:
|
|
|
|
|
case aco_opcode::s_xor_b32:
|
|
|
|
|
case aco_opcode::s_xor_b64:
|
|
|
|
|
return can_eliminate_and_exec(ctx, instr->operands[0].getTemp(), pass_flags) &&
|
|
|
|
|
can_eliminate_and_exec(ctx, instr->operands[1].getTemp(), pass_flags);
|
|
|
|
|
default: return false;
|
2022-03-30 18:01:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
bool
|
|
|
|
|
is_op_canonicalized(opt_ctx& ctx, Operand op)
|
|
|
|
|
{
|
|
|
|
|
float_mode* fp = &ctx.fp_mode;
|
|
|
|
|
if ((op.isTemp() && ctx.info[op.tempId()].is_canonicalized()) ||
|
|
|
|
|
(op.bytes() == 4 ? fp->denorm32 : fp->denorm16_64) == fp_denorm_keep)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (op.isConstant() || (op.isTemp() && ctx.info[op.tempId()].is_constant_or_literal(32))) {
|
|
|
|
|
uint32_t val = op.isTemp() ? ctx.info[op.tempId()].val : op.constantValue();
|
|
|
|
|
if (op.bytes() == 2)
|
|
|
|
|
return (val & 0x7fff) == 0 || (val & 0x7fff) > 0x3ff;
|
|
|
|
|
else if (op.bytes() == 4)
|
|
|
|
|
return (val & 0x7fffffff) == 0 || (val & 0x7fffffff) > 0x7fffff;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 15:19:12 +01:00
|
|
|
bool
|
2022-12-01 15:05:49 +00:00
|
|
|
is_scratch_offset_valid(opt_ctx& ctx, Instruction* instr, int64_t offset0, int64_t offset1)
|
2022-05-19 15:19:12 +01:00
|
|
|
{
|
|
|
|
|
bool negative_unaligned_scratch_offset_bug = ctx.program->gfx_level == GFX10;
|
|
|
|
|
int32_t min = ctx.program->dev.scratch_global_offset_min;
|
|
|
|
|
int32_t max = ctx.program->dev.scratch_global_offset_max;
|
|
|
|
|
|
2022-12-01 15:05:49 +00:00
|
|
|
int64_t offset = offset0 + offset1;
|
|
|
|
|
|
2022-05-19 15:19:12 +01:00
|
|
|
bool has_vgpr_offset = instr && !instr->operands[0].isUndefined();
|
|
|
|
|
if (negative_unaligned_scratch_offset_bug && has_vgpr_offset && offset < 0 && offset % 4)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return offset >= min && offset <= max;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 17:31:06 +01:00
|
|
|
bool
|
|
|
|
|
detect_clamp(Instruction* instr, unsigned* clamped_idx)
|
|
|
|
|
{
|
|
|
|
|
VALU_instruction& valu = instr->valu();
|
|
|
|
|
if (valu.omod != 0 || valu.opsel != 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
unsigned idx = 0;
|
|
|
|
|
bool found_zero = false, found_one = false;
|
|
|
|
|
bool is_fp16 = instr->opcode == aco_opcode::v_med3_f16;
|
|
|
|
|
for (unsigned i = 0; i < 3; i++) {
|
|
|
|
|
if (!valu.neg[i] && instr->operands[i].constantEquals(0))
|
|
|
|
|
found_zero = true;
|
|
|
|
|
else if (!valu.neg[i] &&
|
|
|
|
|
instr->operands[i].constantEquals(is_fp16 ? 0x3c00 : 0x3f800000)) /* 1.0 */
|
|
|
|
|
found_one = true;
|
|
|
|
|
else
|
|
|
|
|
idx = i;
|
|
|
|
|
}
|
|
|
|
|
if (found_zero && found_one && instr->operands[idx].isTemp()) {
|
|
|
|
|
*clamped_idx = idx;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
bool
|
|
|
|
|
parse_operand(opt_ctx& ctx, Temp tmp, alu_opt_op& op_info, aco_type& type)
|
|
|
|
|
{
|
|
|
|
|
ssa_info info = ctx.info[tmp.id()];
|
|
|
|
|
op_info = {};
|
|
|
|
|
type = {};
|
2025-03-27 14:46:00 +01:00
|
|
|
|
|
|
|
|
if (info.parent_instr->opcode == aco_opcode::v_pk_mul_f16 &&
|
|
|
|
|
(info.parent_instr->operands[0].constantEquals(0x3c00) ||
|
|
|
|
|
info.parent_instr->operands[1].constantEquals(0x3c00) ||
|
|
|
|
|
info.parent_instr->operands[0].constantEquals(0xbc00) ||
|
|
|
|
|
info.parent_instr->operands[1].constantEquals(0xbc00))) {
|
|
|
|
|
|
|
|
|
|
VALU_instruction* fneg = &info.parent_instr->valu();
|
|
|
|
|
|
|
|
|
|
unsigned fneg_src =
|
|
|
|
|
fneg->operands[0].constantEquals(0x3c00) || fneg->operands[0].constantEquals(0xbc00);
|
|
|
|
|
|
|
|
|
|
if (fneg->opsel_lo[1 - fneg_src] || fneg->opsel_hi[1 - fneg_src])
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (fneg->clamp || fneg->isDPP())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
type.base_type = aco_base_type_float;
|
|
|
|
|
type.num_components = 2;
|
|
|
|
|
type.bit_size = 16;
|
|
|
|
|
|
|
|
|
|
op_info.op = fneg->operands[fneg_src];
|
|
|
|
|
if (fneg->opsel_lo[fneg_src])
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
if (fneg->opsel_hi[fneg_src])
|
|
|
|
|
op_info.extract[1] = SubdwordSel::uword1;
|
|
|
|
|
op_info.neg[0] =
|
|
|
|
|
fneg->operands[1 - fneg_src].constantEquals(0xbc00) ^ fneg->neg_lo[0] ^ fneg->neg_lo[1];
|
|
|
|
|
op_info.neg[1] =
|
|
|
|
|
fneg->operands[1 - fneg_src].constantEquals(0xbc00) ^ fneg->neg_hi[0] ^ fneg->neg_hi[1];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
// TODO use parent dst type
|
|
|
|
|
if (info.is_fcanonicalize() || info.is_abs() || info.is_neg()) {
|
|
|
|
|
if (ctx.info[info.temp.id()].is_canonicalized() ||
|
|
|
|
|
(tmp.bytes() == 4 ? ctx.fp_mode.denorm32 : ctx.fp_mode.denorm16_64) == fp_denorm_keep)
|
|
|
|
|
type.base_type = aco_base_type_uint;
|
|
|
|
|
else
|
|
|
|
|
type.base_type = aco_base_type_float;
|
|
|
|
|
} else {
|
|
|
|
|
type.base_type = aco_base_type_uint;
|
|
|
|
|
}
|
|
|
|
|
type.num_components = 1;
|
|
|
|
|
type.bit_size = tmp.bytes() * 8;
|
|
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
if (info.is_extract()) {
|
|
|
|
|
op_info.extract[0] = parse_extract(info.parent_instr);
|
|
|
|
|
op_info.op = info.parent_instr->operands[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
if (info.is_constant_or_literal(type.bit_size)) {
|
|
|
|
|
op_info.op = get_constant_op(ctx, info, type.bit_size);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 18:00:17 +01:00
|
|
|
if (info.parent_instr->opcode == aco_opcode::v_cvt_f32_f16 ||
|
|
|
|
|
info.parent_instr->opcode == aco_opcode::s_cvt_f32_f16 ||
|
|
|
|
|
info.parent_instr->opcode == aco_opcode::s_cvt_hi_f32_f16) {
|
|
|
|
|
Instruction* instr = info.parent_instr;
|
|
|
|
|
if (instr->isVALU() && (instr->valu().clamp || instr->valu().omod))
|
|
|
|
|
return false;
|
|
|
|
|
if (instr->isDPP() || (instr->isSDWA() && instr->sdwa().dst_sel.size() != 4))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (instr->isVALU() && instr->valu().abs[0])
|
|
|
|
|
op_info.abs[0] = true;
|
|
|
|
|
if (instr->isVALU() && instr->valu().neg[0])
|
|
|
|
|
op_info.neg[0] = true;
|
|
|
|
|
|
|
|
|
|
if (instr->isSDWA())
|
|
|
|
|
op_info.extract[0] = instr->sdwa().sel[0];
|
|
|
|
|
else if (instr->isVALU() && instr->valu().opsel[0])
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
else if (info.parent_instr->opcode == aco_opcode::s_cvt_hi_f32_f16)
|
|
|
|
|
op_info.extract[0] = SubdwordSel::uword1;
|
|
|
|
|
|
|
|
|
|
op_info.f16_to_f32 = true;
|
|
|
|
|
op_info.op = instr->operands[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
if (info.is_temp() || info.is_fcanonicalize() || info.is_abs() || info.is_neg()) {
|
|
|
|
|
op_info.op = Operand(info.temp);
|
|
|
|
|
if (info.is_abs())
|
|
|
|
|
op_info.abs[0] = true;
|
|
|
|
|
if (info.is_neg())
|
|
|
|
|
op_info.neg[0] = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
combine_operand(opt_ctx& ctx, alu_opt_op& inner, const aco_type& inner_type,
|
|
|
|
|
const alu_opt_op& outer, const aco_type& outer_type, bool flushes_denorms)
|
|
|
|
|
{
|
2024-10-25 12:00:45 +02:00
|
|
|
/* Nothing to be gained by bothering with lane masks. */
|
|
|
|
|
if (inner_type.bit_size <= 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
if (inner.op.size() != outer.op.size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (outer_type.base_type != aco_base_type_uint && !flushes_denorms)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool has_imod = outer.abs[0] || outer.neg[0] || outer.abs[1] || outer.neg[1] ||
|
|
|
|
|
outer_type.base_type != aco_base_type_uint;
|
|
|
|
|
if (has_imod && outer_type.bit_size != inner_type.bit_size)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-11-23 18:00:17 +01:00
|
|
|
if (outer.f16_to_f32) {
|
|
|
|
|
if (inner_type.num_components != 1 || inner.extract[0].size() != 4 || inner.f16_to_f32)
|
|
|
|
|
return false;
|
|
|
|
|
inner.f16_to_f32 = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
for (unsigned i = 0; i < inner_type.num_components; i++) {
|
2025-03-27 14:46:00 +01:00
|
|
|
unsigned offset = inner.extract[i].offset() * 8;
|
|
|
|
|
unsigned size = MIN2(inner.extract[i].size() * 8, inner_type.bit_size);
|
|
|
|
|
unsigned out_comp = offset / outer_type.bit_size;
|
|
|
|
|
unsigned rem_off = offset % outer_type.bit_size;
|
|
|
|
|
if (rem_off && has_imod)
|
|
|
|
|
return false;
|
|
|
|
|
if (out_comp > outer_type.num_components)
|
|
|
|
|
return false;
|
|
|
|
|
if (size > outer_type.bit_size && (out_comp + 1) != outer_type.num_components)
|
|
|
|
|
return false;
|
|
|
|
|
if (rem_off >= outer.extract[out_comp].size() * 8)
|
|
|
|
|
return false;
|
|
|
|
|
if (size < inner_type.bit_size && size > outer.extract[out_comp].size() * 8 &&
|
|
|
|
|
outer.extract[out_comp].sign_extend() && !inner.extract[i].sign_extend())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool sign_extend = size <= outer.extract[out_comp].size() * 8
|
|
|
|
|
? inner.extract[i].sign_extend()
|
|
|
|
|
: outer.extract[out_comp].sign_extend();
|
|
|
|
|
unsigned new_off = (rem_off / 8) + outer.extract[out_comp].offset();
|
|
|
|
|
unsigned new_size = MIN2(size / 8, outer.extract[i].size());
|
|
|
|
|
inner.extract[i] = SubdwordSel(new_size, new_off, sign_extend);
|
|
|
|
|
|
|
|
|
|
if (size == outer_type.bit_size) {
|
|
|
|
|
inner.neg[i] ^= !inner.abs[i] && outer.neg[out_comp];
|
|
|
|
|
inner.abs[i] |= outer.abs[out_comp];
|
|
|
|
|
} else if (outer_type.base_type != aco_base_type_uint) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outer.op.isTemp())
|
|
|
|
|
inner.op.setTemp(outer.op.getTemp());
|
|
|
|
|
else if (inner.op.isFixed())
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
inner.op = outer.op;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-04 17:06:41 +02:00
|
|
|
void
|
|
|
|
|
decrease_and_dce(opt_ctx& ctx, Temp tmp)
|
|
|
|
|
{
|
|
|
|
|
assert(ctx.uses[tmp.id()]);
|
|
|
|
|
ctx.uses[tmp.id()]--;
|
|
|
|
|
Instruction* instr = ctx.info[tmp.id()].parent_instr;
|
|
|
|
|
if (is_dead(ctx.uses, instr)) {
|
|
|
|
|
for (const Operand& op : instr->operands) {
|
|
|
|
|
if (op.isTemp())
|
|
|
|
|
decrease_and_dce(ctx, op.getTemp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
void
|
2024-10-25 12:00:45 +02:00
|
|
|
alu_propagate_temp_const(opt_ctx& ctx, aco_ptr<Instruction>& instr, bool uses_valid)
|
2024-10-21 18:35:22 +02:00
|
|
|
{
|
|
|
|
|
alu_opt_info info;
|
|
|
|
|
if (!alu_opt_gather_info(ctx, instr.get(), info))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool had_lit = std::any_of(info.operands.begin(), info.operands.end(),
|
|
|
|
|
[](const alu_opt_op& op) { return op.op.isLiteral(); });
|
|
|
|
|
|
|
|
|
|
const bool gfx8_min_max =
|
|
|
|
|
ctx.program->gfx_level < GFX9 &&
|
|
|
|
|
(instr->opcode == aco_opcode::v_min_f32 || instr->opcode == aco_opcode::v_max_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_min_f16 || instr->opcode == aco_opcode::v_max_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_min_f64_e64 || instr->opcode == aco_opcode::v_max_f64_e64 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_min3_f32 || instr->opcode == aco_opcode::v_max3_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_med3_f32);
|
|
|
|
|
|
2024-11-23 16:42:42 +01:00
|
|
|
bool remove_extract = !uses_valid;
|
|
|
|
|
/* GFX8: Don't remove label_extract if we can't apply the extract to
|
|
|
|
|
* neg/abs instructions because we'll likely combine it into another valu. */
|
|
|
|
|
if (instr->opcode == aco_opcode::v_mul_f16) {
|
|
|
|
|
for (Operand op : instr->operands)
|
|
|
|
|
remove_extract &= !op.constantEquals(0x3c00) && !op.constantEquals(0xbc00);
|
|
|
|
|
} else if (instr->opcode == aco_opcode::v_mul_f32) {
|
|
|
|
|
for (Operand op : instr->operands)
|
|
|
|
|
remove_extract &= !op.constantEquals(0x3f800000) && !op.constantEquals(0xbf800000);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
unsigned operand_mask = BITFIELD_MASK(info.operands.size());
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
bool progress = false;
|
|
|
|
|
alu_opt_info result_info;
|
2024-10-25 12:00:45 +02:00
|
|
|
while (operand_mask) {
|
|
|
|
|
uint32_t i = UINT32_MAX;
|
|
|
|
|
uint32_t op_uses = UINT32_MAX;
|
|
|
|
|
u_foreach_bit (candidate, operand_mask) {
|
|
|
|
|
if (!info.operands[candidate].op.isTemp()) {
|
|
|
|
|
operand_mask &= ~BITFIELD_BIT(candidate);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
if (!uses_valid) {
|
|
|
|
|
i = candidate;
|
2024-10-21 18:35:22 +02:00
|
|
|
break;
|
2024-10-25 12:00:45 +02:00
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
unsigned new_uses = ctx.uses[info.operands[candidate].op.tempId()];
|
|
|
|
|
if (new_uses >= op_uses)
|
|
|
|
|
continue;
|
|
|
|
|
i = candidate;
|
|
|
|
|
op_uses = new_uses;
|
|
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
if (i == UINT32_MAX)
|
|
|
|
|
break;
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
alu_opt_op outer;
|
|
|
|
|
aco_type outer_type;
|
2024-11-23 18:00:17 +01:00
|
|
|
if (!parse_operand(ctx, info.operands[i].op.getTemp(), outer, outer_type) ||
|
|
|
|
|
(!uses_valid && outer.f16_to_f32)) {
|
2024-10-25 12:00:45 +02:00
|
|
|
operand_mask &= ~BITFIELD_BIT(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
/* Applying SGPRs to VOP1 doesn't increase code size and DCE is helped by doing it earlier,
|
|
|
|
|
* otherwise we apply SGPRs later.
|
|
|
|
|
*/
|
|
|
|
|
bool valu_new_sgpr = info.operands[i].op.isOfType(RegType::vgpr) &&
|
|
|
|
|
outer.op.isOfType(RegType::sgpr) && !instr->isVOP1();
|
2024-11-23 16:42:42 +01:00
|
|
|
if (valu_new_sgpr && !uses_valid) {
|
2024-10-25 12:00:45 +02:00
|
|
|
operand_mask &= ~BITFIELD_BIT(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alu_opt_op inner = info.operands[i];
|
|
|
|
|
aco_type inner_type = get_canonical_operand_type(info.opcode, i);
|
|
|
|
|
if (inner.f16_to_f32)
|
|
|
|
|
inner_type.bit_size = 16;
|
|
|
|
|
bool flushes_denorms = inner_type.base_type == aco_base_type_float && !gfx8_min_max;
|
|
|
|
|
if (!combine_operand(ctx, inner, inner_type, outer, outer_type, flushes_denorms)) {
|
2024-11-23 16:42:42 +01:00
|
|
|
if (remove_extract)
|
|
|
|
|
ctx.info[info.operands[i].op.tempId()].label &= ~label_extract;
|
2024-10-25 12:00:45 +02:00
|
|
|
operand_mask &= ~BITFIELD_BIT(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-21 18:35:22 +02:00
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
alu_opt_info info_copy = info;
|
|
|
|
|
info_copy.operands[i] = inner;
|
|
|
|
|
if (!alu_opt_info_is_valid(ctx, info_copy)) {
|
2024-11-23 16:42:42 +01:00
|
|
|
if (remove_extract)
|
|
|
|
|
ctx.info[info.operands[i].op.tempId()].label &= ~label_extract;
|
2024-10-25 12:00:45 +02:00
|
|
|
operand_mask &= ~BITFIELD_BIT(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
bool has_lit = std::any_of(info_copy.operands.begin(), info_copy.operands.end(),
|
|
|
|
|
[](const alu_opt_op& op) { return op.op.isLiteral(); });
|
|
|
|
|
|
2024-11-23 16:42:42 +01:00
|
|
|
if ((!had_lit && has_lit) ||
|
|
|
|
|
(ctx.info[info.operands[i].op.tempId()].is_extract() && !uses_valid)) {
|
2024-10-25 12:00:45 +02:00
|
|
|
operand_mask &= ~BITFIELD_BIT(i);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool valu_removed_sgpr = info.operands[i].op.isOfType(RegType::sgpr) &&
|
|
|
|
|
!inner.op.isOfType(RegType::sgpr) && instr->isVALU();
|
|
|
|
|
if (valu_removed_sgpr && uses_valid)
|
|
|
|
|
operand_mask = BITFIELD_MASK(info.operands.size());
|
|
|
|
|
|
|
|
|
|
if (uses_valid) {
|
|
|
|
|
if (inner.op.isTemp())
|
|
|
|
|
ctx.uses[inner.op.tempId()]++;
|
|
|
|
|
decrease_and_dce(ctx, info.operands[i].op.getTemp());
|
2024-10-21 18:35:22 +02:00
|
|
|
}
|
2024-10-25 12:00:45 +02:00
|
|
|
|
|
|
|
|
result_info = info_copy;
|
|
|
|
|
info.operands[i] = inner;
|
|
|
|
|
progress = true;
|
2024-10-21 18:35:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!progress)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
instr.reset(alu_opt_info_to_instr(ctx, result_info, instr.release()));
|
|
|
|
|
for (const Definition& def : instr->definitions)
|
|
|
|
|
ctx.info[def.tempId()].label &= instr_mod_labels | label_canonicalized;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 16:10:19 +01:00
|
|
|
void
|
|
|
|
|
extract_apply_extract(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (!ctx.info[instr->operands[0].tempId()].is_extract())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
alu_opt_op outer;
|
|
|
|
|
aco_type outer_type;
|
|
|
|
|
if (!parse_operand(ctx, instr->operands[0].getTemp(), outer, outer_type))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (instr->definitions[0].bytes() < 4 && outer.op.isOfType(RegType::sgpr) &&
|
|
|
|
|
ctx.program->gfx_level < GFX9)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
alu_opt_op inner = {};
|
|
|
|
|
inner.op = instr->operands[0];
|
|
|
|
|
inner.extract[0] = parse_extract(instr.get());
|
|
|
|
|
if (!inner.extract[0])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
aco_type inner_type = {};
|
|
|
|
|
inner_type.base_type = aco_base_type_uint;
|
|
|
|
|
inner_type.num_components = 1;
|
|
|
|
|
inner_type.bit_size = instr->definitions[0].bytes() * 8;
|
|
|
|
|
|
|
|
|
|
if (!combine_operand(ctx, inner, inner_type, outer, outer_type, false))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(inner.extract[0].size() <= 2);
|
|
|
|
|
|
|
|
|
|
aco_opcode new_opcode = inner.extract[0].size() == instr->definitions[0].bytes()
|
|
|
|
|
? aco_opcode::p_extract_vector
|
|
|
|
|
: aco_opcode::p_extract;
|
|
|
|
|
|
|
|
|
|
if (new_opcode != instr->opcode) {
|
|
|
|
|
assert(instr->definitions[0].regClass().type() == RegType::vgpr);
|
|
|
|
|
|
|
|
|
|
unsigned new_ops = new_opcode == aco_opcode::p_extract_vector ? 2 : 4;
|
|
|
|
|
Instruction* new_instr = create_instruction(new_opcode, Format::PSEUDO, new_ops, 1);
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
|
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
|
|
|
|
instr.reset(new_instr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instr->operands[0] = inner.op;
|
|
|
|
|
if (instr->opcode == aco_opcode::p_extract_vector) {
|
|
|
|
|
instr->operands[1] = Operand::c32(inner.extract[0].offset() / instr->definitions[0].bytes());
|
|
|
|
|
} else {
|
|
|
|
|
instr->operands[1] = Operand::c32(inner.extract[0].offset() / inner.extract[0].size());
|
|
|
|
|
instr->operands[2] = Operand::c32(inner.extract[0].size() * 8u);
|
|
|
|
|
instr->operands[3] = Operand::c32(inner.extract[0].sign_extend());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
void
|
|
|
|
|
label_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2021-12-14 19:51:50 +00:00
|
|
|
if (instr->isSMEM())
|
|
|
|
|
smem_combine(ctx, instr);
|
aco: skip &-4 before SMEM
The hardware ignores the low 2 bits. I'm not sure if they are ignored
before or after the address is calculated, but this optimization should be
cautious enough.
fossil-db (Sienna Cichlid):
Totals from 259 (0.19% of 134572) affected shaders:
SpillSGPRs: 1381 -> 1382 (+0.07%)
SpillVGPRs: 1783 -> 1782 (-0.06%); split: -0.67%, +0.62%
CodeSize: 1598612 -> 1596084 (-0.16%); split: -0.30%, +0.14%
Scratch: 180224 -> 179200 (-0.57%); split: -1.14%, +0.57%
Instrs: 284885 -> 284268 (-0.22%); split: -0.34%, +0.12%
Latency: 6585634 -> 6603388 (+0.27%); split: -0.48%, +0.75%
InvThroughput: 2638983 -> 2648474 (+0.36%); split: -0.58%, +0.94%
VClause: 6797 -> 6820 (+0.34%); split: -0.15%, +0.49%
SClause: 6569 -> 6574 (+0.08%); split: -1.11%, +1.19%
Copies: 50561 -> 50586 (+0.05%); split: -0.61%, +0.66%
Branches: 10058 -> 10062 (+0.04%); split: -0.01%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13755>
2021-11-11 10:54:56 +00:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
if (!instr->operands[i].isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ssa_info info = ctx.info[instr->operands[i].tempId()];
|
|
|
|
|
/* propagate reg->reg of same type */
|
2020-12-31 11:01:08 +00:00
|
|
|
while (info.is_temp() && info.temp.regClass() == instr->operands[i].getTemp().regClass()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->operands[i].setTemp(ctx.info[instr->operands[i].tempId()].temp);
|
|
|
|
|
info = ctx.info[info.temp.id()];
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
/* PSEUDO: propagate temporaries/constants */
|
2021-01-20 15:27:16 +00:00
|
|
|
if (instr->isPseudo()) {
|
2020-12-31 11:01:08 +00:00
|
|
|
while (info.is_temp()) {
|
|
|
|
|
pseudo_propagate_temp(ctx, instr, info.temp, i);
|
2020-04-07 10:46:37 +01:00
|
|
|
info = ctx.info[info.temp.id()];
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2025-05-16 12:09:08 +02:00
|
|
|
unsigned bits = instr->operands[i].bytes() * 8u;
|
2024-10-21 18:35:22 +02:00
|
|
|
if (info.is_constant_or_literal(bits) && pseudo_can_accept_constant(instr, i)) {
|
2020-05-15 16:28:03 +01:00
|
|
|
instr->operands[i] = get_constant_op(ctx, info, bits);
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* MUBUF: propagate constants and combine additions */
|
2021-01-20 15:27:16 +00:00
|
|
|
else if (instr->isMUBUF()) {
|
2021-01-21 16:13:34 +00:00
|
|
|
MUBUF_instruction& mubuf = instr->mubuf();
|
2019-09-17 13:22:17 +02:00
|
|
|
Temp base;
|
|
|
|
|
uint32_t offset;
|
|
|
|
|
while (info.is_temp())
|
|
|
|
|
info = ctx.info[info.temp.id()];
|
|
|
|
|
|
2024-06-07 13:46:11 +01:00
|
|
|
bool swizzled = ctx.program->gfx_level >= GFX12 ? mubuf.cache.gfx12.swizzled
|
|
|
|
|
: (mubuf.cache.value & ac_swizzled);
|
2019-10-15 17:00:55 +01:00
|
|
|
/* According to AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(), vaddr
|
|
|
|
|
* overflow for scratch accesses works only on GFX9+ and saddr overflow
|
|
|
|
|
* never works. Since swizzling is the only thing that separates
|
|
|
|
|
* scratch accesses and other accesses and swizzling changing how
|
|
|
|
|
* addressing works significantly, this probably applies to swizzled
|
|
|
|
|
* MUBUF accesses. */
|
2024-05-14 18:34:01 +01:00
|
|
|
bool vaddr_prevent_overflow = swizzled && ctx.program->gfx_level < GFX9;
|
2019-10-15 17:00:55 +01:00
|
|
|
|
2025-04-23 17:01:48 +01:00
|
|
|
uint32_t const_max = ctx.program->dev.buf_offset_max;
|
|
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (mubuf.offen && mubuf.idxen && i == 1 &&
|
|
|
|
|
info.parent_instr->opcode == aco_opcode::p_create_vector &&
|
2024-07-23 17:49:32 +02:00
|
|
|
info.parent_instr->operands.size() == 2 && info.parent_instr->operands[0].isTemp() &&
|
|
|
|
|
info.parent_instr->operands[0].regClass() == v1 &&
|
|
|
|
|
info.parent_instr->operands[1].isConstant() &&
|
|
|
|
|
mubuf.offset + info.parent_instr->operands[1].constantValue() <= const_max) {
|
|
|
|
|
instr->operands[1] = info.parent_instr->operands[0];
|
|
|
|
|
mubuf.offset += info.parent_instr->operands[1].constantValue();
|
2022-04-20 17:21:11 +02:00
|
|
|
mubuf.offen = false;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (mubuf.offen && i == 1 && info.is_constant_or_literal(32) &&
|
2025-04-23 17:01:48 +01:00
|
|
|
mubuf.offset + info.val <= const_max) {
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!mubuf.idxen);
|
2020-01-16 16:54:35 +01:00
|
|
|
instr->operands[1] = Operand(v1);
|
2021-01-21 16:13:34 +00:00
|
|
|
mubuf.offset += info.val;
|
|
|
|
|
mubuf.offen = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
2025-04-23 17:01:48 +01:00
|
|
|
} else if (i == 2 && info.is_constant_or_literal(32) &&
|
|
|
|
|
mubuf.offset + info.val <= const_max) {
|
2021-07-13 11:22:46 +02:00
|
|
|
instr->operands[2] = Operand::c32(0);
|
2021-01-21 16:13:34 +00:00
|
|
|
mubuf.offset += info.val;
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
2021-01-21 16:13:34 +00:00
|
|
|
} else if (mubuf.offen && i == 1 &&
|
|
|
|
|
parse_base_offset(ctx, instr.get(), i, &base, &offset,
|
|
|
|
|
vaddr_prevent_overflow) &&
|
2025-04-23 17:01:48 +01:00
|
|
|
base.regClass() == v1 && mubuf.offset + offset <= const_max) {
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!mubuf.idxen);
|
2020-01-16 16:54:35 +01:00
|
|
|
instr->operands[1].setTemp(base);
|
2021-01-21 16:13:34 +00:00
|
|
|
mubuf.offset += offset;
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
2022-03-25 12:03:27 +01:00
|
|
|
} else if (i == 2 && parse_base_offset(ctx, instr.get(), i, &base, &offset, true) &&
|
2025-04-23 17:01:48 +01:00
|
|
|
base.regClass() == s1 && mubuf.offset + offset <= const_max && !swizzled) {
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->operands[i].setTemp(base);
|
2021-01-21 16:13:34 +00:00
|
|
|
mubuf.offset += offset;
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-03 00:32:06 +01:00
|
|
|
else if (instr->isMTBUF()) {
|
|
|
|
|
MTBUF_instruction& mtbuf = instr->mtbuf();
|
|
|
|
|
while (info.is_temp())
|
|
|
|
|
info = ctx.info[info.temp.id()];
|
|
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (mtbuf.offen && mtbuf.idxen && i == 1 &&
|
|
|
|
|
info.parent_instr->opcode == aco_opcode::p_create_vector &&
|
2024-07-23 17:49:32 +02:00
|
|
|
info.parent_instr->operands.size() == 2 && info.parent_instr->operands[0].isTemp() &&
|
|
|
|
|
info.parent_instr->operands[0].regClass() == v1 &&
|
|
|
|
|
info.parent_instr->operands[1].isConstant() &&
|
|
|
|
|
mtbuf.offset + info.parent_instr->operands[1].constantValue() <=
|
2025-04-23 17:01:48 +01:00
|
|
|
ctx.program->dev.buf_offset_max) {
|
2024-07-23 17:49:32 +02:00
|
|
|
instr->operands[1] = info.parent_instr->operands[0];
|
|
|
|
|
mtbuf.offset += info.parent_instr->operands[1].constantValue();
|
2023-02-03 00:32:06 +01:00
|
|
|
mtbuf.offen = false;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 15:19:12 +01:00
|
|
|
/* SCRATCH: propagate constants and combine additions */
|
|
|
|
|
else if (instr->isScratch()) {
|
|
|
|
|
FLAT_instruction& scratch = instr->scratch();
|
|
|
|
|
Temp base;
|
|
|
|
|
uint32_t offset;
|
|
|
|
|
while (info.is_temp())
|
|
|
|
|
info = ctx.info[info.temp.id()];
|
|
|
|
|
|
2022-12-01 15:05:49 +00:00
|
|
|
/* The hardware probably does: 'scratch_base + u2u64(saddr) + i2i64(offset)'. This means
|
|
|
|
|
* we can't combine the addition if the unsigned addition overflows and offset is
|
|
|
|
|
* positive. In theory, there is also issues if
|
|
|
|
|
* 'ilt(offset, 0) && ige(saddr, 0) && ilt(saddr + offset, 0)', but that just
|
|
|
|
|
* replaces an already out-of-bounds access with a larger one since 'saddr + offset'
|
|
|
|
|
* would be larger than INT32_MAX.
|
|
|
|
|
*/
|
|
|
|
|
if (i <= 1 && parse_base_offset(ctx, instr.get(), i, &base, &offset, true) &&
|
2022-05-19 15:19:12 +01:00
|
|
|
base.regClass() == instr->operands[i].regClass() &&
|
2022-12-01 15:05:49 +00:00
|
|
|
is_scratch_offset_valid(ctx, instr.get(), scratch.offset, (int32_t)offset)) {
|
|
|
|
|
instr->operands[i].setTemp(base);
|
|
|
|
|
scratch.offset += (int32_t)offset;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (i <= 1 && parse_base_offset(ctx, instr.get(), i, &base, &offset, false) &&
|
|
|
|
|
base.regClass() == instr->operands[i].regClass() && (int32_t)offset < 0 &&
|
|
|
|
|
is_scratch_offset_valid(ctx, instr.get(), scratch.offset, (int32_t)offset)) {
|
2022-05-19 15:19:12 +01:00
|
|
|
instr->operands[i].setTemp(base);
|
|
|
|
|
scratch.offset += (int32_t)offset;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (i <= 1 && info.is_constant_or_literal(32) &&
|
|
|
|
|
ctx.program->gfx_level >= GFX10_3 &&
|
2022-12-01 15:05:49 +00:00
|
|
|
is_scratch_offset_valid(ctx, NULL, scratch.offset, (int32_t)info.val)) {
|
2022-05-19 15:19:12 +01:00
|
|
|
/* GFX10.3+ can disable both SADDR and ADDR. */
|
|
|
|
|
instr->operands[i] = Operand(instr->operands[i].regClass());
|
|
|
|
|
scratch.offset += (int32_t)info.val;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 15:27:16 +00:00
|
|
|
else if (instr->isBranch()) {
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
if (ctx.info[instr->operands[0].tempId()].is_scc_invert()) {
|
|
|
|
|
/* Flip the branch instruction to get rid of the scc_invert instruction */
|
|
|
|
|
instr->opcode = instr->opcode == aco_opcode::p_cbranch_z ? aco_opcode::p_cbranch_nz
|
|
|
|
|
: aco_opcode::p_cbranch_z;
|
|
|
|
|
instr->operands[0].setTemp(ctx.info[instr->operands[0].tempId()].temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:35:22 +02:00
|
|
|
/* SALU / VALU: propagate inline constants, temps, and imod */
|
|
|
|
|
if (instr->isSALU() || instr->isVALU()) {
|
2024-10-25 12:00:45 +02:00
|
|
|
alu_propagate_temp_const(ctx, instr, false);
|
2024-10-21 18:35:22 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* if this instruction doesn't define anything, return */
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
if (instr->definitions.empty()) {
|
2024-11-23 16:42:42 +01:00
|
|
|
remove_operand_extract(ctx, instr);
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-11-23 16:10:19 +01:00
|
|
|
if (instr->opcode == aco_opcode::p_extract || instr->opcode == aco_opcode::p_extract_vector)
|
|
|
|
|
extract_apply_extract(ctx, instr);
|
|
|
|
|
|
2025-03-10 13:29:13 +01:00
|
|
|
if (instr->isVALU() || (instr->isVINTRP() && instr->opcode != aco_opcode::v_interp_mov_f32)) {
|
2025-04-29 15:55:47 +02:00
|
|
|
if (instr_info.alu_opcode_infos[(int)instr->opcode].output_modifiers || instr->isVINTRP() ||
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
instr->opcode == aco_opcode::v_cndmask_b32) {
|
|
|
|
|
bool canonicalized = true;
|
|
|
|
|
if (!does_fp_op_flush_denorms(ctx, instr->opcode)) {
|
|
|
|
|
unsigned ops = instr->opcode == aco_opcode::v_cndmask_b32 ? 2 : instr->operands.size();
|
|
|
|
|
for (unsigned i = 0; canonicalized && (i < ops); i++)
|
|
|
|
|
canonicalized = is_op_canonicalized(ctx, instr->operands[i]);
|
|
|
|
|
}
|
|
|
|
|
if (canonicalized)
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_canonicalized();
|
|
|
|
|
}
|
2020-09-03 12:02:55 +01:00
|
|
|
}
|
2020-06-19 16:09:48 +01:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::p_create_vector: {
|
2020-05-06 17:24:38 +01:00
|
|
|
bool copy_prop = instr->operands.size() == 1 && instr->operands[0].isTemp() &&
|
|
|
|
|
instr->operands[0].regClass() == instr->definitions[0].regClass();
|
|
|
|
|
if (copy_prop) {
|
2020-04-21 17:37:44 +01:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp());
|
2020-05-06 17:24:38 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2020-04-21 17:37:44 +01:00
|
|
|
|
2020-09-18 11:52:35 +01:00
|
|
|
/* expand vector operands */
|
|
|
|
|
std::vector<Operand> ops;
|
2020-12-31 11:04:11 +00:00
|
|
|
unsigned offset = 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (const Operand& op : instr->operands) {
|
2020-12-31 11:04:11 +00:00
|
|
|
/* ensure that any expanded operands are properly aligned */
|
|
|
|
|
bool aligned = offset % 4 == 0 || op.bytes() < 4;
|
|
|
|
|
offset += op.bytes();
|
2024-07-30 11:31:15 +02:00
|
|
|
if (aligned && op.isTemp() &&
|
|
|
|
|
ctx.info[op.tempId()].parent_instr->opcode == aco_opcode::p_create_vector) {
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* vec = ctx.info[op.tempId()].parent_instr;
|
2020-12-31 11:04:11 +00:00
|
|
|
for (const Operand& vec_op : vec->operands)
|
2020-09-18 11:52:35 +01:00
|
|
|
ops.emplace_back(vec_op);
|
|
|
|
|
} else {
|
|
|
|
|
ops.emplace_back(op);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-24 11:58:17 +01:00
|
|
|
|
aco/optimizer: generalize p_create_vector of split vector opt
Foz-DB Navi48:
Totals from 116 (0.14% of 80251) affected shaders:
MaxWaves: 2965 -> 2972 (+0.24%)
Instrs: 145933 -> 144632 (-0.89%); split: -0.91%, +0.02%
CodeSize: 815968 -> 806512 (-1.16%); split: -1.20%, +0.04%
VGPRs: 7240 -> 7144 (-1.33%); split: -1.66%, +0.33%
Latency: 3065858 -> 3063802 (-0.07%); split: -0.11%, +0.05%
InvThroughput: 745395 -> 743506 (-0.25%); split: -0.26%, +0.01%
VClause: 3702 -> 3694 (-0.22%); split: -0.65%, +0.43%
SClause: 3187 -> 3191 (+0.13%)
Copies: 12716 -> 11804 (-7.17%); split: -7.42%, +0.25%
Branches: 3501 -> 3503 (+0.06%)
PreVGPRs: 5400 -> 5327 (-1.35%); split: -1.41%, +0.06%
VALU: 76455 -> 75492 (-1.26%); split: -1.30%, +0.04%
SALU: 23594 -> 23595 (+0.00%); split: -0.00%, +0.01%
VOPD: 1478 -> 1527 (+3.32%); split: +4.67%, -1.35%
Mostly helps FSR4.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35674>
2025-06-22 15:07:20 +02:00
|
|
|
offset = 0;
|
|
|
|
|
for (unsigned i = 0; i < ops.size(); i++) {
|
|
|
|
|
if (ops[i].isTemp()) {
|
|
|
|
|
if (ctx.info[ops[i].tempId()].is_temp() &&
|
|
|
|
|
ops[i].regClass() == ctx.info[ops[i].tempId()].temp.regClass()) {
|
|
|
|
|
ops[i].setTemp(ctx.info[ops[i].tempId()].temp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If this and the following operands make up all definitions of a `p_split_vector`,
|
|
|
|
|
* replace them with the operand of the `p_split_vector` instruction.
|
|
|
|
|
*/
|
|
|
|
|
Instruction* parent = ctx.info[ops[i].tempId()].parent_instr;
|
|
|
|
|
if (parent->opcode == aco_opcode::p_split_vector &&
|
|
|
|
|
(offset % 4 == 0 || parent->operands[0].bytes() < 4) &&
|
|
|
|
|
parent->definitions.size() <= ops.size() - i) {
|
|
|
|
|
copy_prop = true;
|
|
|
|
|
for (unsigned j = 0; copy_prop && j < parent->definitions.size(); j++) {
|
|
|
|
|
copy_prop &= ops[i + j].isTemp() &&
|
|
|
|
|
ops[i + j].getTemp() == parent->definitions[j].getTemp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (copy_prop) {
|
|
|
|
|
ops.erase(ops.begin() + i + 1, ops.begin() + i + parent->definitions.size());
|
|
|
|
|
ops[i] = parent->operands[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset += ops[i].bytes();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 11:52:35 +01:00
|
|
|
/* combine expanded operands to new vector */
|
aco/optimizer: generalize p_create_vector of split vector opt
Foz-DB Navi48:
Totals from 116 (0.14% of 80251) affected shaders:
MaxWaves: 2965 -> 2972 (+0.24%)
Instrs: 145933 -> 144632 (-0.89%); split: -0.91%, +0.02%
CodeSize: 815968 -> 806512 (-1.16%); split: -1.20%, +0.04%
VGPRs: 7240 -> 7144 (-1.33%); split: -1.66%, +0.33%
Latency: 3065858 -> 3063802 (-0.07%); split: -0.11%, +0.05%
InvThroughput: 745395 -> 743506 (-0.25%); split: -0.26%, +0.01%
VClause: 3702 -> 3694 (-0.22%); split: -0.65%, +0.43%
SClause: 3187 -> 3191 (+0.13%)
Copies: 12716 -> 11804 (-7.17%); split: -7.42%, +0.25%
Branches: 3501 -> 3503 (+0.06%)
PreVGPRs: 5400 -> 5327 (-1.35%); split: -1.41%, +0.06%
VALU: 76455 -> 75492 (-1.26%); split: -1.30%, +0.04%
SALU: 23594 -> 23595 (+0.00%); split: -0.00%, +0.01%
VOPD: 1478 -> 1527 (+3.32%); split: +4.67%, -1.35%
Mostly helps FSR4.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35674>
2025-06-22 15:07:20 +02:00
|
|
|
if (ops.size() <= instr->operands.size()) {
|
|
|
|
|
while (instr->operands.size() > ops.size())
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
|
2025-08-24 13:41:05 +02:00
|
|
|
if (ops.size() == 1 && !ops[0].isUndefined()) {
|
aco/optimizer: generalize p_create_vector of split vector opt
Foz-DB Navi48:
Totals from 116 (0.14% of 80251) affected shaders:
MaxWaves: 2965 -> 2972 (+0.24%)
Instrs: 145933 -> 144632 (-0.89%); split: -0.91%, +0.02%
CodeSize: 815968 -> 806512 (-1.16%); split: -1.20%, +0.04%
VGPRs: 7240 -> 7144 (-1.33%); split: -1.66%, +0.33%
Latency: 3065858 -> 3063802 (-0.07%); split: -0.11%, +0.05%
InvThroughput: 745395 -> 743506 (-0.25%); split: -0.26%, +0.01%
VClause: 3702 -> 3694 (-0.22%); split: -0.65%, +0.43%
SClause: 3187 -> 3191 (+0.13%)
Copies: 12716 -> 11804 (-7.17%); split: -7.42%, +0.25%
Branches: 3501 -> 3503 (+0.06%)
PreVGPRs: 5400 -> 5327 (-1.35%); split: -1.41%, +0.06%
VALU: 76455 -> 75492 (-1.26%); split: -1.30%, +0.04%
SALU: 23594 -> 23595 (+0.00%); split: -0.00%, +0.01%
VOPD: 1478 -> 1527 (+3.32%); split: +4.67%, -1.35%
Mostly helps FSR4.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35674>
2025-06-22 15:07:20 +02:00
|
|
|
instr->opcode = aco_opcode::p_parallelcopy;
|
|
|
|
|
if (ops[0].isTemp())
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(ops[0].getTemp());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-09-18 11:52:35 +01:00
|
|
|
Definition def = instr->definitions[0];
|
2024-03-25 15:55:27 +01:00
|
|
|
instr.reset(
|
|
|
|
|
create_instruction(aco_opcode::p_create_vector, Format::PSEUDO, ops.size(), 1));
|
2020-09-18 11:52:35 +01:00
|
|
|
instr->definitions[0] = def;
|
|
|
|
|
}
|
2022-03-16 15:14:29 +01:00
|
|
|
|
aco/optimizer: generalize p_create_vector of split vector opt
Foz-DB Navi48:
Totals from 116 (0.14% of 80251) affected shaders:
MaxWaves: 2965 -> 2972 (+0.24%)
Instrs: 145933 -> 144632 (-0.89%); split: -0.91%, +0.02%
CodeSize: 815968 -> 806512 (-1.16%); split: -1.20%, +0.04%
VGPRs: 7240 -> 7144 (-1.33%); split: -1.66%, +0.33%
Latency: 3065858 -> 3063802 (-0.07%); split: -0.11%, +0.05%
InvThroughput: 745395 -> 743506 (-0.25%); split: -0.26%, +0.01%
VClause: 3702 -> 3694 (-0.22%); split: -0.65%, +0.43%
SClause: 3187 -> 3191 (+0.13%)
Copies: 12716 -> 11804 (-7.17%); split: -7.42%, +0.25%
Branches: 3501 -> 3503 (+0.06%)
PreVGPRs: 5400 -> 5327 (-1.35%); split: -1.41%, +0.06%
VALU: 76455 -> 75492 (-1.26%); split: -1.30%, +0.04%
SALU: 23594 -> 23595 (+0.00%); split: -0.00%, +0.01%
VOPD: 1478 -> 1527 (+3.32%); split: +4.67%, -1.35%
Mostly helps FSR4.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35674>
2025-06-22 15:07:20 +02:00
|
|
|
for (unsigned i = 0; i < ops.size(); i++)
|
|
|
|
|
instr->operands[i] = ops[i];
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::p_split_vector: {
|
2020-05-18 19:42:40 +01:00
|
|
|
ssa_info& info = ctx.info[instr->operands[0].tempId()];
|
|
|
|
|
|
|
|
|
|
if (info.is_constant_or_literal(32)) {
|
2021-11-25 07:36:10 +01:00
|
|
|
uint64_t val = info.val;
|
2020-05-18 19:42:40 +01:00
|
|
|
for (Definition def : instr->definitions) {
|
|
|
|
|
uint32_t mask = u_bit_consecutive(0, def.bytes() * 8u);
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.info[def.tempId()].set_constant(ctx.program->gfx_level, val & mask);
|
2020-05-18 19:42:40 +01:00
|
|
|
val >>= def.bytes() * 8u;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-07-30 11:31:15 +02:00
|
|
|
} else if (info.parent_instr->opcode != aco_opcode::p_create_vector) {
|
2022-03-16 15:14:29 +01:00
|
|
|
if (instr->definitions.size() == 2 && instr->operands[0].isTemp() &&
|
|
|
|
|
instr->definitions[0].bytes() == instr->definitions[1].bytes()) {
|
|
|
|
|
if (instr->operands[0].bytes() == 4) {
|
|
|
|
|
/* D16 subdword split */
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp());
|
2024-07-30 15:43:44 +02:00
|
|
|
ctx.info[instr->definitions[1].tempId()].set_extract();
|
2022-03-16 15:14:29 +01:00
|
|
|
}
|
aco/optimizer: apply extract from subdword p_split_vector
Totals from 1345 (1.00% of 134572) affected shaders: (GFX10.3)
VGPRs: 76752 -> 76744 (-0.01%); split: -0.02%, +0.01%
SpillSGPRs: 1459 -> 1460 (+0.07%)
SpillVGPRs: 1776 -> 1784 (+0.45%); split: -0.39%, +0.84%
CodeSize: 13310964 -> 13309420 (-0.01%); split: -0.06%, +0.05%
Scratch: 178176 -> 179200 (+0.57%)
Instrs: 2516874 -> 2516860 (-0.00%); split: -0.05%, +0.05%
Latency: 23228506 -> 23230338 (+0.01%); split: -0.14%, +0.15%
InvThroughput: 6002384 -> 6000158 (-0.04%); split: -0.24%, +0.21%
VClause: 41115 -> 41117 (+0.00%); split: -0.28%, +0.29%
SClause: 104639 -> 104664 (+0.02%); split: -0.07%, +0.09%
Copies: 185121 -> 184862 (-0.14%); split: -0.69%, +0.55%
Branches: 100740 -> 100735 (-0.00%); split: -0.01%, +0.00%
PreVGPRs: 70119 -> 69968 (-0.22%)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13576>
2021-10-25 16:44:42 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
2020-05-18 19:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
Instruction* vec = info.parent_instr;
|
2020-04-10 13:09:54 +01:00
|
|
|
unsigned split_offset = 0;
|
|
|
|
|
unsigned vec_offset = 0;
|
|
|
|
|
unsigned vec_index = 0;
|
|
|
|
|
for (unsigned i = 0; i < instr->definitions.size();
|
|
|
|
|
split_offset += instr->definitions[i++].bytes()) {
|
|
|
|
|
while (vec_offset < split_offset && vec_index < vec->operands.size())
|
|
|
|
|
vec_offset += vec->operands[vec_index++].bytes();
|
|
|
|
|
|
|
|
|
|
if (vec_offset != split_offset ||
|
|
|
|
|
vec->operands[vec_index].bytes() != instr->definitions[i].bytes())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Operand vec_op = vec->operands[vec_index];
|
2019-09-17 13:22:17 +02:00
|
|
|
if (vec_op.isConstant()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.info[instr->definitions[i].tempId()].set_constant(ctx.program->gfx_level,
|
2020-05-15 16:28:03 +01:00
|
|
|
vec_op.constantValue64());
|
2024-05-17 18:00:09 +02:00
|
|
|
} else if (vec_op.isTemp()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[instr->definitions[i].tempId()].set_temp(vec_op.getTemp());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::p_extract_vector: { /* mov */
|
2020-05-18 19:42:40 +01:00
|
|
|
const unsigned index = instr->operands[1].constantValue();
|
|
|
|
|
|
2024-06-06 17:14:31 +01:00
|
|
|
if (instr->operands[0].isTemp()) {
|
|
|
|
|
ssa_info& info = ctx.info[instr->operands[0].tempId()];
|
|
|
|
|
const unsigned dst_offset = index * instr->definitions[0].bytes();
|
2021-01-15 09:23:04 +01:00
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (info.parent_instr->opcode == aco_opcode::p_create_vector) {
|
2024-06-06 17:14:31 +01:00
|
|
|
/* check if we index directly into a vector element */
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* vec = info.parent_instr;
|
2024-06-06 17:14:31 +01:00
|
|
|
unsigned offset = 0;
|
|
|
|
|
|
|
|
|
|
for (const Operand& op : vec->operands) {
|
|
|
|
|
if (offset < dst_offset) {
|
|
|
|
|
offset += op.bytes();
|
|
|
|
|
continue;
|
|
|
|
|
} else if (offset != dst_offset || op.bytes() != instr->definitions[0].bytes()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
instr->operands[0] = op;
|
2021-01-15 09:23:04 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2024-06-06 17:14:31 +01:00
|
|
|
} else if (info.is_constant_or_literal(32)) {
|
|
|
|
|
/* propagate constants */
|
|
|
|
|
uint32_t mask = u_bit_consecutive(0, instr->definitions[0].bytes() * 8u);
|
|
|
|
|
uint32_t val = (info.val >> (dst_offset * 8u)) & mask;
|
|
|
|
|
instr->operands[0] =
|
|
|
|
|
Operand::get_const(ctx.program->gfx_level, val, instr->definitions[0].bytes());
|
|
|
|
|
;
|
2020-04-10 11:52:13 +01:00
|
|
|
}
|
2021-01-15 09:23:04 +01:00
|
|
|
}
|
2019-11-13 11:14:51 +01:00
|
|
|
|
2021-10-04 11:13:08 +01:00
|
|
|
if (instr->operands[0].bytes() != instr->definitions[0].bytes()) {
|
2024-06-06 17:14:31 +01:00
|
|
|
if (instr->operands[0].size() != 1 || !instr->operands[0].isTemp())
|
2021-10-04 11:13:08 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp());
|
|
|
|
|
else
|
2024-07-30 15:43:44 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_extract();
|
2020-04-10 11:52:13 +01:00
|
|
|
break;
|
2021-10-04 11:13:08 +01:00
|
|
|
}
|
2021-01-15 09:23:04 +01:00
|
|
|
|
|
|
|
|
/* convert this extract into a copy instruction */
|
|
|
|
|
instr->opcode = aco_opcode::p_parallelcopy;
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
FALLTHROUGH;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2020-10-15 15:18:40 +01:00
|
|
|
case aco_opcode::p_parallelcopy: /* propagate */
|
2024-07-30 11:31:15 +02:00
|
|
|
if (instr->operands[0].isTemp() &&
|
|
|
|
|
ctx.info[instr->operands[0].tempId()].parent_instr->opcode ==
|
|
|
|
|
aco_opcode::p_create_vector &&
|
2020-10-15 14:49:34 +01:00
|
|
|
instr->operands[0].regClass() != instr->definitions[0].regClass()) {
|
|
|
|
|
/* We might not be able to copy-propagate if it's a SGPR->VGPR copy, so
|
|
|
|
|
* duplicate the vector instead.
|
|
|
|
|
*/
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* vec = ctx.info[instr->operands[0].tempId()].parent_instr;
|
2020-10-15 14:49:34 +01:00
|
|
|
aco_ptr<Instruction> old_copy = std::move(instr);
|
|
|
|
|
|
2024-03-25 15:55:27 +01:00
|
|
|
instr.reset(create_instruction(aco_opcode::p_create_vector, Format::PSEUDO,
|
|
|
|
|
vec->operands.size(), 1));
|
2020-10-15 14:49:34 +01:00
|
|
|
instr->definitions[0] = old_copy->definitions[0];
|
|
|
|
|
std::copy(vec->operands.begin(), vec->operands.end(), instr->operands.begin());
|
|
|
|
|
for (unsigned i = 0; i < vec->operands.size(); i++) {
|
|
|
|
|
Operand& op = instr->operands[i];
|
|
|
|
|
if (op.isTemp() && ctx.info[op.tempId()].is_temp() &&
|
|
|
|
|
ctx.info[op.tempId()].temp.type() == instr->definitions[0].regClass().type())
|
|
|
|
|
op.setTemp(ctx.info[op.tempId()].temp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-01 09:54:31 +00:00
|
|
|
FALLTHROUGH;
|
2019-09-17 13:22:17 +02:00
|
|
|
case aco_opcode::p_as_uniform:
|
|
|
|
|
if (instr->definitions[0].isFixed()) {
|
|
|
|
|
/* don't copy-propagate copies into fixed registers */
|
|
|
|
|
} else if (instr->operands[0].isConstant()) {
|
2020-05-15 16:28:03 +01:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_constant(
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.program->gfx_level, instr->operands[0].constantValue64());
|
2019-09-17 13:22:17 +02:00
|
|
|
} else if (instr->operands[0].isTemp()) {
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp());
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
if (ctx.info[instr->operands[0].tempId()].is_canonicalized())
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_canonicalized();
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
assert(instr->operands[0].isFixed());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case aco_opcode::p_is_helper:
|
|
|
|
|
if (!ctx.program->needs_wqm)
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_constant(ctx.program->gfx_level, 0u);
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
2020-05-15 15:12:33 +01:00
|
|
|
case aco_opcode::v_mul_f16:
|
2021-09-21 17:03:05 +01:00
|
|
|
case aco_opcode::v_mul_f32:
|
|
|
|
|
case aco_opcode::v_mul_legacy_f32: { /* omod */
|
2019-09-17 13:22:17 +02:00
|
|
|
/* TODO: try to move the negate/abs modifier to the consumer instead */
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
bool uses_mods = instr->usesModifiers();
|
2020-05-15 15:12:33 +01:00
|
|
|
bool fp16 = instr->opcode == aco_opcode::v_mul_f16;
|
2024-11-26 16:28:58 +01:00
|
|
|
unsigned denorm_mode = fp16 ? ctx.fp_mode.denorm16_64 : ctx.fp_mode.denorm32;
|
2020-05-15 15:12:33 +01:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (instr->operands[!i].isConstant() && instr->operands[i].isTemp()) {
|
2023-03-24 13:35:07 +01:00
|
|
|
if (!instr->isDPP() && !instr->isSDWA() && !instr->valu().opsel &&
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
(instr->operands[!i].constantEquals(fp16 ? 0x3c00 : 0x3f800000) || /* 1.0 */
|
|
|
|
|
instr->operands[!i].constantEquals(fp16 ? 0xbc00 : 0xbf800000u))) { /* -1.0 */
|
|
|
|
|
bool neg1 = instr->operands[!i].constantEquals(fp16 ? 0xbc00 : 0xbf800000u);
|
|
|
|
|
|
2023-12-04 14:23:05 +00:00
|
|
|
VALU_instruction* valu = &instr->valu();
|
|
|
|
|
if (valu->abs[!i] || valu->neg[!i] || valu->omod)
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
continue;
|
|
|
|
|
|
2023-12-04 14:23:05 +00:00
|
|
|
bool abs = valu->abs[i];
|
|
|
|
|
bool neg = neg1 ^ valu->neg[i];
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
Temp other = instr->operands[i].getTemp();
|
2023-12-01 16:20:38 +00:00
|
|
|
|
2023-12-04 14:23:05 +00:00
|
|
|
if (valu->clamp) {
|
2023-12-01 16:20:38 +00:00
|
|
|
if (!abs && !neg && other.type() == RegType::vgpr)
|
|
|
|
|
ctx.info[other.id()].set_clamp(instr.get());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
if (abs && neg && other.type() == RegType::vgpr)
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_neg_abs(other);
|
|
|
|
|
else if (abs && !neg && other.type() == RegType::vgpr)
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_abs(other);
|
|
|
|
|
else if (!abs && neg && other.type() == RegType::vgpr)
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_neg(other);
|
2024-11-26 16:28:58 +01:00
|
|
|
else if (!abs && !neg) {
|
|
|
|
|
if (denorm_mode == fp_denorm_keep || ctx.info[other.id()].is_canonicalized())
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(other);
|
|
|
|
|
else
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_fcanonicalize(other);
|
|
|
|
|
}
|
2024-09-13 20:06:46 +02:00
|
|
|
} else if (uses_mods || (instr->definitions[0].isSZPreserve() &&
|
2023-09-22 14:10:52 +02:00
|
|
|
instr->opcode != aco_opcode::v_mul_legacy_f32)) {
|
|
|
|
|
continue; /* omod uses a legacy multiplication. */
|
2024-09-13 20:06:46 +02:00
|
|
|
} else if (instr->operands[!i].constantValue() == 0u &&
|
|
|
|
|
((!instr->definitions[0].isNaNPreserve() &&
|
|
|
|
|
!instr->definitions[0].isInfPreserve()) ||
|
|
|
|
|
instr->opcode == aco_opcode::v_mul_legacy_f32)) { /* 0.0 */
|
2023-09-22 14:10:52 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_constant(ctx.program->gfx_level, 0u);
|
2024-11-26 16:28:58 +01:00
|
|
|
} else if (denorm_mode != fp_denorm_flush) {
|
2023-09-22 14:10:52 +02:00
|
|
|
/* omod has no effect if denormals are enabled. */
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
continue;
|
|
|
|
|
} else if (instr->operands[!i].constantValue() ==
|
|
|
|
|
(fp16 ? 0x4000 : 0x40000000)) { /* 2.0 */
|
2020-08-12 15:58:32 +01:00
|
|
|
ctx.info[instr->operands[i].tempId()].set_omod2(instr.get());
|
2020-05-15 15:12:33 +01:00
|
|
|
} else if (instr->operands[!i].constantValue() ==
|
|
|
|
|
(fp16 ? 0x4400 : 0x40800000)) { /* 4.0 */
|
2020-08-12 15:58:32 +01:00
|
|
|
ctx.info[instr->operands[i].tempId()].set_omod4(instr.get());
|
2020-11-13 15:12:21 +00:00
|
|
|
} else if (instr->operands[!i].constantValue() ==
|
|
|
|
|
(fp16 ? 0x3800 : 0x3f000000)) { /* 0.5 */
|
2020-08-12 15:58:32 +01:00
|
|
|
ctx.info[instr->operands[i].tempId()].set_omod5(instr.get());
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-07-15 18:59:56 +02:00
|
|
|
case aco_opcode::v_med3_f16:
|
|
|
|
|
case aco_opcode::v_med3_f32: { /* clamp */
|
|
|
|
|
unsigned idx;
|
|
|
|
|
if (detect_clamp(instr.get(), &idx) && !instr->valu().abs && !instr->valu().neg)
|
|
|
|
|
ctx.info[instr->operands[idx].tempId()].set_clamp(instr.get());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::v_cndmask_b32:
|
|
|
|
|
if (instr->operands[0].constantEquals(0) && instr->operands[1].constantEquals(0x3f800000u))
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_b2f(instr->operands[2].getTemp());
|
|
|
|
|
else if (instr->operands[0].constantEquals(0) && instr->operands[1].constantEquals(1))
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_b2i(instr->operands[2].getTemp());
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
case aco_opcode::s_not_b32:
|
|
|
|
|
case aco_opcode::s_not_b64:
|
2024-01-19 19:53:28 +00:00
|
|
|
if (!instr->operands[0].isTemp()) {
|
|
|
|
|
} else if (ctx.info[instr->operands[0].tempId()].is_uniform_bool()) {
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_uniform_bitwise();
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].set_scc_invert(
|
|
|
|
|
ctx.info[instr->operands[0].tempId()].temp);
|
|
|
|
|
} else if (ctx.info[instr->operands[0].tempId()].is_uniform_bitwise()) {
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_uniform_bitwise();
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].set_scc_invert(
|
2024-07-23 17:49:32 +02:00
|
|
|
ctx.info[instr->operands[0].tempId()].parent_instr->definitions[1].getTemp());
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
}
|
|
|
|
|
break;
|
2019-11-22 11:57:45 +01:00
|
|
|
case aco_opcode::s_and_b32:
|
2019-11-05 11:41:00 +01:00
|
|
|
case aco_opcode::s_and_b64:
|
2020-01-28 12:04:48 +00:00
|
|
|
if (fixed_to_exec(instr->operands[1]) && instr->operands[0].isTemp()) {
|
2020-01-03 10:30:04 +01:00
|
|
|
if (ctx.info[instr->operands[0].tempId()].is_uniform_bool()) {
|
|
|
|
|
/* Try to get rid of the superfluous s_cselect + s_and_b64 that comes from turning a
|
|
|
|
|
* uniform bool into divergent */
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].set_temp(
|
|
|
|
|
ctx.info[instr->operands[0].tempId()].temp);
|
|
|
|
|
break;
|
|
|
|
|
} else if (ctx.info[instr->operands[0].tempId()].is_uniform_bitwise()) {
|
|
|
|
|
/* Try to get rid of the superfluous s_and_b64, since the uniform bitwise instruction
|
|
|
|
|
* already produces the same SCC */
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].set_temp(
|
2024-07-23 17:49:32 +02:00
|
|
|
ctx.info[instr->operands[0].tempId()].parent_instr->definitions[1].getTemp());
|
2020-01-03 10:30:04 +01:00
|
|
|
break;
|
2021-06-18 15:25:35 +02:00
|
|
|
} else if ((ctx.program->stage.num_sw_stages() > 1 ||
|
2023-05-13 17:55:54 +02:00
|
|
|
ctx.program->stage.hw == AC_HW_NEXT_GEN_GEOMETRY_SHADER) &&
|
2021-06-18 15:25:35 +02:00
|
|
|
instr->pass_flags == 1) {
|
|
|
|
|
/* In case of merged shaders, pass_flags=1 means that all lanes are active (exec=-1), so
|
|
|
|
|
* s_and is unnecessary. */
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_temp(instr->operands[0].getTemp());
|
|
|
|
|
break;
|
2020-01-03 10:30:04 +01:00
|
|
|
}
|
2019-11-05 11:41:00 +01:00
|
|
|
}
|
2020-12-01 09:54:31 +00:00
|
|
|
FALLTHROUGH;
|
2019-09-17 13:22:17 +02:00
|
|
|
case aco_opcode::s_or_b32:
|
|
|
|
|
case aco_opcode::s_or_b64:
|
|
|
|
|
case aco_opcode::s_xor_b32:
|
|
|
|
|
case aco_opcode::s_xor_b64:
|
2020-01-03 10:30:04 +01:00
|
|
|
if (std::all_of(instr->operands.begin(), instr->operands.end(),
|
|
|
|
|
[&ctx](const Operand& op)
|
|
|
|
|
{
|
|
|
|
|
return op.isTemp() && (ctx.info[op.tempId()].is_uniform_bool() ||
|
|
|
|
|
ctx.info[op.tempId()].is_uniform_bitwise());
|
|
|
|
|
})) {
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_uniform_bitwise();
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
2019-11-05 11:41:00 +01:00
|
|
|
case aco_opcode::s_cselect_b64:
|
2019-11-22 11:57:45 +01:00
|
|
|
case aco_opcode::s_cselect_b32:
|
2019-11-05 11:41:00 +01:00
|
|
|
if (instr->operands[0].constantEquals((unsigned)-1) && instr->operands[1].constantEquals(0)) {
|
|
|
|
|
/* Found a cselect that operates on a uniform bool that comes from eg. s_cmp */
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_uniform_bool(instr->operands[2].getTemp());
|
2025-07-16 16:00:06 +01:00
|
|
|
} else if (instr->operands[2].isTemp() && ctx.info[instr->operands[2].tempId()].is_scc_invert()) {
|
aco: Flip s_cbranch / s_cselect to optimize out an s_not if possible.
When possible, get rid of an s_not when all it does is invert the SCC,
and its successor s_cbranch / s_cselect can be inverted instead.
Also modify some parts of instruction_selection to take advantage of
this feature.
Example:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
s2: %3902 = s_cselect_b64 -1, 0, %3900:scc
s2: %407, s1: %3903:scc = s_not_b64 %3902
s2: %3906, s1: %3905:scc = s_and_b64 %407, %0:exec
p_cbranch_z %3905:scc
Can now be optimized to:
s2: %3900, s1: %3899:scc = s_andn2_b64 %0:exec, %406
p_cbranch_nz %3900:scc
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
2019-11-19 13:29:54 +01:00
|
|
|
/* Flip the operands to get rid of the scc_invert instruction */
|
|
|
|
|
std::swap(instr->operands[0], instr->operands[1]);
|
|
|
|
|
instr->operands[2].setTemp(ctx.info[instr->operands[2].tempId()].temp);
|
|
|
|
|
}
|
|
|
|
|
break;
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
case aco_opcode::s_mul_i32:
|
|
|
|
|
/* Testing every uint32_t shows that 0x3f800000*n is never a denormal.
|
|
|
|
|
* This pattern is created from a uniform nir_op_b2f. */
|
|
|
|
|
if (instr->operands[0].constantEquals(0x3f800000u))
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].set_canonicalized();
|
|
|
|
|
break;
|
2020-08-12 14:35:15 +01:00
|
|
|
case aco_opcode::p_extract: {
|
2024-10-22 10:41:04 +01:00
|
|
|
if (instr->operands[0].isTemp()) {
|
2024-07-30 15:43:44 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_extract();
|
2024-10-22 10:41:04 +01:00
|
|
|
if (instr->definitions[0].bytes() == 4 && instr->operands[0].regClass() == v1 &&
|
|
|
|
|
parse_insert(instr.get()))
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
ctx.info[instr->operands[0].tempId()].set_insert(instr.get());
|
|
|
|
|
}
|
2020-08-12 14:35:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::p_insert: {
|
2024-10-22 10:41:04 +01:00
|
|
|
if (instr->operands[0].isTemp()) {
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
if (instr->operands[0].regClass() == v1)
|
|
|
|
|
ctx.info[instr->operands[0].tempId()].set_insert(instr.get());
|
2021-08-30 17:58:36 +02:00
|
|
|
if (parse_extract(instr.get()))
|
2024-07-30 15:43:44 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_extract();
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
}
|
2020-08-12 14:35:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2022-01-17 16:52:10 +00:00
|
|
|
case aco_opcode::v_cvt_f16_f32: {
|
2024-07-30 11:31:15 +02:00
|
|
|
if (instr->operands[0].isTemp())
|
|
|
|
|
ctx.info[instr->operands[0].tempId()].set_f2f16(instr.get());
|
2022-01-17 16:52:10 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
default: break;
|
|
|
|
|
}
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
2024-11-23 16:42:42 +01:00
|
|
|
remove_operand_extract(ctx, instr);
|
2024-07-24 12:28:36 +02:00
|
|
|
|
|
|
|
|
/* Set parent_instr for all SSA definitions. */
|
|
|
|
|
for (const Definition& def : instr->definitions)
|
|
|
|
|
ctx.info[def.tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
|
original_temp_id(opt_ctx& ctx, Temp tmp)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.info[tmp.id()].is_temp())
|
|
|
|
|
return ctx.info[tmp.id()].temp.id();
|
|
|
|
|
else
|
|
|
|
|
return tmp.id();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 13:45:25 +02:00
|
|
|
Operand
|
|
|
|
|
copy_operand(opt_ctx& ctx, Operand op)
|
|
|
|
|
{
|
|
|
|
|
if (op.isTemp())
|
|
|
|
|
ctx.uses[op.tempId()]++;
|
|
|
|
|
return op;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
Instruction*
|
|
|
|
|
follow_operand(opt_ctx& ctx, Operand op, bool ignore_uses = false)
|
|
|
|
|
{
|
2024-07-30 11:31:15 +02:00
|
|
|
if (!op.isTemp())
|
2019-09-17 13:22:17 +02:00
|
|
|
return nullptr;
|
|
|
|
|
if (!ignore_uses && ctx.uses[op.tempId()] > 1)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* instr = ctx.info[op.tempId()].parent_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
if (instr->definitions[0].getTemp() != op.getTemp())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
if (instr->definitions.size() == 2) {
|
2024-07-15 20:02:58 +02:00
|
|
|
unsigned idx =
|
|
|
|
|
instr->definitions[1].isTemp() && instr->definitions[1].tempId() == op.tempId();
|
2024-06-06 18:10:15 +01:00
|
|
|
assert(instr->definitions[idx].isTemp() && instr->definitions[idx].tempId() == op.tempId());
|
|
|
|
|
if (instr->definitions[!idx].isTemp() && ctx.uses[instr->definitions[!idx].tempId()])
|
2019-09-17 13:22:17 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 14:37:19 +02:00
|
|
|
for (Operand& operand : instr->operands) {
|
|
|
|
|
if (fixed_to_exec(operand))
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
return instr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-07 11:40:45 +01:00
|
|
|
bool
|
|
|
|
|
is_operand_constant(opt_ctx& ctx, Operand op, unsigned bit_size, uint64_t* value)
|
|
|
|
|
{
|
|
|
|
|
if (op.isConstant()) {
|
|
|
|
|
*value = op.constantValue64();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (op.isTemp()) {
|
|
|
|
|
unsigned id = original_temp_id(ctx, op.getTemp());
|
|
|
|
|
if (!ctx.info[id].is_constant_or_literal(bit_size))
|
|
|
|
|
return false;
|
|
|
|
|
*value = get_constant_op(ctx, ctx.info[id], bit_size).constantValue64();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-30 18:54:30 +02:00
|
|
|
/* s_not(cmp(a, b)) -> get_vcmp_inverse(cmp)(a, b) */
|
2019-09-17 13:22:17 +02:00
|
|
|
bool
|
|
|
|
|
combine_inverse_comparison(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2019-12-16 15:35:14 +00:00
|
|
|
if (ctx.uses[instr->definitions[1].tempId()])
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
2022-08-24 19:13:52 +02:00
|
|
|
if (!instr->operands[0].isTemp() || ctx.uses[instr->operands[0].tempId()] != 1)
|
|
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2022-08-20 22:55:45 +02:00
|
|
|
Instruction* cmp = follow_operand(ctx, instr->operands[0]);
|
2019-09-17 13:22:17 +02:00
|
|
|
if (!cmp)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-05-30 18:54:30 +02:00
|
|
|
aco_opcode new_opcode = get_vcmp_inverse(cmp->opcode);
|
2020-05-19 13:26:21 +01:00
|
|
|
if (new_opcode == aco_opcode::num_opcodes)
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
2022-08-24 19:13:52 +02:00
|
|
|
/* Invert compare instruction and assign this instruction's definition */
|
|
|
|
|
cmp->opcode = new_opcode;
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()] = ctx.info[cmp->definitions[0].tempId()];
|
|
|
|
|
std::swap(instr->definitions[0], cmp->definitions[0]);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[cmp->definitions[0].tempId()].parent_instr = cmp;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2022-08-24 19:13:52 +02:00
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
2019-09-17 13:22:17 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* op1(op2(1, 2), 0) if swap = false
|
|
|
|
|
* op1(0, op2(1, 2)) if swap = true */
|
2021-06-09 10:14:54 +02:00
|
|
|
bool
|
2019-09-17 13:22:17 +02:00
|
|
|
match_op3_for_vop3(opt_ctx& ctx, aco_opcode op1, aco_opcode op2, Instruction* op1_instr, bool swap,
|
2023-03-08 16:30:39 +01:00
|
|
|
const char* shuffle_str, Operand operands[3], bitarray8& neg, bitarray8& abs,
|
|
|
|
|
bitarray8& opsel, bool* op1_clamp, uint8_t* op1_omod, bool* inbetween_neg,
|
2020-10-07 11:09:16 +01:00
|
|
|
bool* inbetween_abs, bool* inbetween_opsel, bool* precise)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
/* checks */
|
|
|
|
|
if (op1_instr->opcode != op1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Instruction* op2_instr = follow_operand(ctx, op1_instr->operands[swap]);
|
|
|
|
|
if (!op2_instr || op2_instr->opcode != op2)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-03-22 19:31:17 +01:00
|
|
|
VALU_instruction* op1_valu = op1_instr->isVALU() ? &op1_instr->valu() : NULL;
|
|
|
|
|
VALU_instruction* op2_valu = op2_instr->isVALU() ? &op2_instr->valu() : NULL;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-12-05 14:12:39 +00:00
|
|
|
if (op1_instr->isSDWA() || op2_instr->isSDWA())
|
|
|
|
|
return false;
|
2021-07-19 14:26:42 +01:00
|
|
|
if (op1_instr->isDPP() || op2_instr->isDPP())
|
|
|
|
|
return false;
|
2019-12-05 14:12:39 +00:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* don't support inbetween clamp/omod */
|
2023-03-22 19:31:17 +01:00
|
|
|
if (op2_valu && (op2_valu->clamp || op2_valu->omod))
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* get operands and modifiers and check inbetween modifiers */
|
2023-03-22 19:31:17 +01:00
|
|
|
*op1_clamp = op1_valu ? (bool)op1_valu->clamp : false;
|
|
|
|
|
*op1_omod = op1_valu ? (unsigned)op1_valu->omod : 0u;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
if (inbetween_neg)
|
2023-03-22 19:31:17 +01:00
|
|
|
*inbetween_neg = op1_valu ? op1_valu->neg[swap] : false;
|
|
|
|
|
else if (op1_valu && op1_valu->neg[swap])
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (inbetween_abs)
|
2023-03-22 19:31:17 +01:00
|
|
|
*inbetween_abs = op1_valu ? op1_valu->abs[swap] : false;
|
|
|
|
|
else if (op1_valu && op1_valu->abs[swap])
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (inbetween_opsel)
|
2023-03-22 19:31:17 +01:00
|
|
|
*inbetween_opsel = op1_valu ? op1_valu->opsel[swap] : false;
|
|
|
|
|
else if (op1_valu && op1_valu->opsel[swap])
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
2020-10-07 11:09:16 +01:00
|
|
|
*precise = op1_instr->definitions[0].isPrecise() || op2_instr->definitions[0].isPrecise();
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
int shuffle[3];
|
|
|
|
|
shuffle[shuffle_str[0] - '0'] = 0;
|
|
|
|
|
shuffle[shuffle_str[1] - '0'] = 1;
|
|
|
|
|
shuffle[shuffle_str[2] - '0'] = 2;
|
|
|
|
|
|
|
|
|
|
operands[shuffle[0]] = op1_instr->operands[!swap];
|
2023-03-22 19:31:17 +01:00
|
|
|
neg[shuffle[0]] = op1_valu ? op1_valu->neg[!swap] : false;
|
|
|
|
|
abs[shuffle[0]] = op1_valu ? op1_valu->abs[!swap] : false;
|
|
|
|
|
opsel[shuffle[0]] = op1_valu ? op1_valu->opsel[!swap] : false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
operands[shuffle[i + 1]] = op2_instr->operands[i];
|
2023-03-22 19:31:17 +01:00
|
|
|
neg[shuffle[i + 1]] = op2_valu ? op2_valu->neg[i] : false;
|
|
|
|
|
abs[shuffle[i + 1]] = op2_valu ? op2_valu->abs[i] : false;
|
|
|
|
|
opsel[shuffle[i + 1]] = op2_valu ? op2_valu->opsel[i] : false;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check operands */
|
2019-11-22 14:50:41 +00:00
|
|
|
if (!check_vop3_operands(ctx, 3, operands))
|
|
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
create_vop3_for_op3(opt_ctx& ctx, aco_opcode opcode, aco_ptr<Instruction>& instr,
|
2023-03-08 16:30:39 +01:00
|
|
|
Operand operands[3], uint8_t neg, uint8_t abs, uint8_t opsel, bool clamp,
|
2019-09-17 13:22:17 +02:00
|
|
|
unsigned omod)
|
|
|
|
|
{
|
2024-03-25 15:55:27 +01:00
|
|
|
Instruction* new_instr = create_instruction(opcode, Format::VOP3, 3, 1);
|
2024-03-25 12:05:50 +01:00
|
|
|
new_instr->valu().neg = neg;
|
|
|
|
|
new_instr->valu().abs = abs;
|
|
|
|
|
new_instr->valu().clamp = clamp;
|
|
|
|
|
new_instr->valu().omod = omod;
|
|
|
|
|
new_instr->valu().opsel = opsel;
|
2019-09-17 13:22:17 +02:00
|
|
|
new_instr->operands[0] = operands[0];
|
|
|
|
|
new_instr->operands[1] = operands[1];
|
|
|
|
|
new_instr->operands[2] = operands[2];
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
2023-05-09 20:24:52 +02:00
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = new_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
instr.reset(new_instr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
combine_three_valu_op(opt_ctx& ctx, aco_ptr<Instruction>& instr, aco_opcode op2, aco_opcode new_op,
|
|
|
|
|
const char* shuffle, uint8_t ops)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned swap = 0; swap < 2; swap++) {
|
|
|
|
|
if (!((1 << swap) & ops))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Operand operands[3];
|
2023-03-08 16:30:39 +01:00
|
|
|
bool clamp, precise;
|
|
|
|
|
bitarray8 neg = 0, abs = 0, opsel = 0;
|
|
|
|
|
uint8_t omod = 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
if (match_op3_for_vop3(ctx, instr->opcode, op2, instr.get(), swap, shuffle, operands, neg,
|
2023-03-08 16:30:39 +01:00
|
|
|
abs, opsel, &clamp, &omod, NULL, NULL, NULL, &precise)) {
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.uses[instr->operands[swap].tempId()]--;
|
|
|
|
|
create_vop3_for_op3(ctx, new_op, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 14:35:15 +01:00
|
|
|
/* creates v_lshl_add_u32, v_lshl_or_b32 or v_and_or_b32 */
|
|
|
|
|
bool
|
|
|
|
|
combine_add_or_then_and_lshl(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
bool is_or = instr->opcode == aco_opcode::v_or_b32;
|
|
|
|
|
aco_opcode new_op_lshl = is_or ? aco_opcode::v_lshl_or_b32 : aco_opcode::v_lshl_add_u32;
|
|
|
|
|
|
|
|
|
|
if (is_or && combine_three_valu_op(ctx, instr, aco_opcode::s_and_b32, aco_opcode::v_and_or_b32,
|
|
|
|
|
"120", 1 | 2))
|
|
|
|
|
return true;
|
|
|
|
|
if (is_or && combine_three_valu_op(ctx, instr, aco_opcode::v_and_b32, aco_opcode::v_and_or_b32,
|
|
|
|
|
"120", 1 | 2))
|
|
|
|
|
return true;
|
|
|
|
|
if (combine_three_valu_op(ctx, instr, aco_opcode::s_lshl_b32, new_op_lshl, "120", 1 | 2))
|
|
|
|
|
return true;
|
|
|
|
|
if (combine_three_valu_op(ctx, instr, aco_opcode::v_lshlrev_b32, new_op_lshl, "210", 1 | 2))
|
|
|
|
|
return true;
|
|
|
|
|
|
2021-07-19 14:26:42 +01:00
|
|
|
if (instr->isSDWA() || instr->isDPP())
|
2020-08-12 14:35:15 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* v_or_b32(p_extract(a, 0, 8/16, 0), b) -> v_and_or_b32(a, 0xff/0xffff, b)
|
|
|
|
|
* v_or_b32(p_insert(a, 0, 8/16), b) -> v_and_or_b32(a, 0xff/0xffff, b)
|
|
|
|
|
* v_or_b32(p_insert(a, 24/16, 8/16), b) -> v_lshl_or_b32(a, 24/16, b)
|
|
|
|
|
* v_add_u32(p_insert(a, 24/16, 8/16), b) -> v_lshl_add_b32(a, 24/16, b)
|
|
|
|
|
*/
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
Instruction* extins = follow_operand(ctx, instr->operands[i]);
|
|
|
|
|
if (!extins)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
aco_opcode op;
|
|
|
|
|
Operand operands[3];
|
|
|
|
|
|
|
|
|
|
if (extins->opcode == aco_opcode::p_insert &&
|
|
|
|
|
(extins->operands[1].constantValue() + 1) * extins->operands[2].constantValue() == 32) {
|
|
|
|
|
op = new_op_lshl;
|
|
|
|
|
operands[1] =
|
2021-07-13 11:22:46 +02:00
|
|
|
Operand::c32(extins->operands[1].constantValue() * extins->operands[2].constantValue());
|
2020-08-12 14:35:15 +01:00
|
|
|
} else if (is_or &&
|
|
|
|
|
(extins->opcode == aco_opcode::p_insert ||
|
|
|
|
|
(extins->opcode == aco_opcode::p_extract &&
|
|
|
|
|
extins->operands[3].constantEquals(0))) &&
|
|
|
|
|
extins->operands[1].constantEquals(0)) {
|
|
|
|
|
op = aco_opcode::v_and_or_b32;
|
2021-07-13 11:22:46 +02:00
|
|
|
operands[1] = Operand::c32(extins->operands[2].constantEquals(8) ? 0xffu : 0xffffu);
|
2020-08-12 14:35:15 +01:00
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operands[0] = extins->operands[0];
|
|
|
|
|
operands[2] = instr->operands[!i];
|
|
|
|
|
|
|
|
|
|
if (!check_vop3_operands(ctx, 3, operands))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-03-08 16:30:39 +01:00
|
|
|
uint8_t neg = 0, abs = 0, opsel = 0, omod = 0;
|
2020-08-12 14:35:15 +01:00
|
|
|
bool clamp = false;
|
|
|
|
|
if (instr->isVOP3())
|
2023-02-21 20:08:42 +01:00
|
|
|
clamp = instr->valu().clamp;
|
2020-08-12 14:35:15 +01:00
|
|
|
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
create_vop3_for_op3(ctx, op, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 14:18:15 +01:00
|
|
|
/* v_xor(a, s_not(b)) -> v_xnor(a, b)
|
|
|
|
|
* v_xor(a, v_not(b)) -> v_xnor(a, b)
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
combine_xor_not(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[i], true);
|
|
|
|
|
if (!op_instr ||
|
|
|
|
|
(op_instr->opcode != aco_opcode::v_not_b32 &&
|
|
|
|
|
op_instr->opcode != aco_opcode::s_not_b32) ||
|
|
|
|
|
op_instr->usesModifiers() || op_instr->operands[0].isLiteral())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
instr->opcode = aco_opcode::v_xnor_b32;
|
|
|
|
|
instr->operands[i] = copy_operand(ctx, op_instr->operands[0]);
|
2025-06-04 17:06:41 +02:00
|
|
|
decrease_and_dce(ctx, op_instr->definitions[0].getTemp());
|
2023-02-08 14:18:15 +01:00
|
|
|
if (instr->operands[0].isOfType(RegType::vgpr))
|
|
|
|
|
std::swap(instr->operands[0], instr->operands[1]);
|
|
|
|
|
if (!instr->operands[1].isOfType(RegType::vgpr))
|
2023-03-07 13:28:28 +01:00
|
|
|
instr->format = asVOP3(instr->format);
|
2023-02-08 14:18:15 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* v_not(v_xor(a, b)) -> v_xnor(a, b) */
|
|
|
|
|
bool
|
|
|
|
|
combine_not_xor(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[0]);
|
|
|
|
|
if (!op_instr || op_instr->opcode != aco_opcode::v_xor_b32 || op_instr->isSDWA())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
|
|
|
|
std::swap(instr->definitions[0], op_instr->definitions[0]);
|
|
|
|
|
op_instr->opcode = aco_opcode::v_xnor_b32;
|
2024-06-10 14:31:32 +01:00
|
|
|
ctx.info[op_instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[op_instr->definitions[0].tempId()].parent_instr = op_instr;
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2023-02-08 14:18:15 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 20:32:11 +00:00
|
|
|
bool
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
combine_minmax(opt_ctx& ctx, aco_ptr<Instruction>& instr, aco_opcode opposite, aco_opcode op3src,
|
|
|
|
|
aco_opcode minmax)
|
2019-11-22 20:32:11 +00:00
|
|
|
{
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
/* TODO: this can handle SDWA min/max instructions by using opsel */
|
2019-11-22 20:32:11 +00:00
|
|
|
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
/* min(min(a, b), c) -> min3(a, b, c)
|
|
|
|
|
* max(max(a, b), c) -> max3(a, b, c)
|
|
|
|
|
* gfx11: min(-min(a, b), c) -> maxmin(-a, -b, c)
|
|
|
|
|
* gfx11: max(-max(a, b), c) -> minmax(-a, -b, c)
|
|
|
|
|
*/
|
|
|
|
|
for (unsigned swap = 0; swap < 2; swap++) {
|
|
|
|
|
Operand operands[3];
|
2023-03-08 16:30:39 +01:00
|
|
|
bool clamp, precise;
|
|
|
|
|
bitarray8 opsel = 0, neg = 0, abs = 0;
|
|
|
|
|
uint8_t omod = 0;
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
bool inbetween_neg;
|
|
|
|
|
if (match_op3_for_vop3(ctx, instr->opcode, instr->opcode, instr.get(), swap, "120", operands,
|
2023-03-08 16:30:39 +01:00
|
|
|
neg, abs, opsel, &clamp, &omod, &inbetween_neg, NULL, NULL,
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
&precise) &&
|
|
|
|
|
(!inbetween_neg ||
|
|
|
|
|
(minmax != aco_opcode::num_opcodes && ctx.program->gfx_level >= GFX11))) {
|
|
|
|
|
ctx.uses[instr->operands[swap].tempId()]--;
|
|
|
|
|
if (inbetween_neg) {
|
|
|
|
|
neg[0] = !neg[0];
|
|
|
|
|
neg[1] = !neg[1];
|
|
|
|
|
create_vop3_for_op3(ctx, minmax, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
} else {
|
|
|
|
|
create_vop3_for_op3(ctx, op3src, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* min(-max(a, b), c) -> min3(-a, -b, c)
|
|
|
|
|
* max(-min(a, b), c) -> max3(-a, -b, c)
|
|
|
|
|
* gfx11: min(max(a, b), c) -> maxmin(a, b, c)
|
|
|
|
|
* gfx11: max(min(a, b), c) -> minmax(a, b, c)
|
|
|
|
|
*/
|
2019-11-22 20:32:11 +00:00
|
|
|
for (unsigned swap = 0; swap < 2; swap++) {
|
|
|
|
|
Operand operands[3];
|
2023-03-08 16:30:39 +01:00
|
|
|
bool clamp, precise;
|
|
|
|
|
bitarray8 opsel = 0, neg = 0, abs = 0;
|
|
|
|
|
uint8_t omod = 0;
|
2019-11-22 20:32:11 +00:00
|
|
|
bool inbetween_neg;
|
2022-11-16 18:10:38 +00:00
|
|
|
if (match_op3_for_vop3(ctx, instr->opcode, opposite, instr.get(), swap, "120", operands, neg,
|
2023-03-08 16:30:39 +01:00
|
|
|
abs, opsel, &clamp, &omod, &inbetween_neg, NULL, NULL, &precise) &&
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
(inbetween_neg ||
|
|
|
|
|
(minmax != aco_opcode::num_opcodes && ctx.program->gfx_level >= GFX11))) {
|
2019-11-22 20:32:11 +00:00
|
|
|
ctx.uses[instr->operands[swap].tempId()]--;
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
if (inbetween_neg) {
|
|
|
|
|
neg[0] = !neg[0];
|
|
|
|
|
neg[1] = !neg[1];
|
|
|
|
|
create_vop3_for_op3(ctx, op3src, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
} else {
|
|
|
|
|
create_vop3_for_op3(ctx, minmax, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
}
|
2019-11-22 20:32:11 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* s_not_b32(s_and_b32(a, b)) -> s_nand_b32(a, b)
|
|
|
|
|
* s_not_b32(s_or_b32(a, b)) -> s_nor_b32(a, b)
|
|
|
|
|
* s_not_b32(s_xor_b32(a, b)) -> s_xnor_b32(a, b)
|
|
|
|
|
* s_not_b64(s_and_b64(a, b)) -> s_nand_b64(a, b)
|
|
|
|
|
* s_not_b64(s_or_b64(a, b)) -> s_nor_b64(a, b)
|
|
|
|
|
* s_not_b64(s_xor_b64(a, b)) -> s_xnor_b64(a, b) */
|
|
|
|
|
bool
|
|
|
|
|
combine_salu_not_bitwise(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
/* checks */
|
|
|
|
|
if (!instr->operands[0].isTemp())
|
|
|
|
|
return false;
|
|
|
|
|
if (instr->definitions[1].isTemp() && ctx.uses[instr->definitions[1].tempId()])
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Instruction* op2_instr = follow_operand(ctx, instr->operands[0]);
|
|
|
|
|
if (!op2_instr)
|
|
|
|
|
return false;
|
|
|
|
|
switch (op2_instr->opcode) {
|
|
|
|
|
case aco_opcode::s_and_b32:
|
|
|
|
|
case aco_opcode::s_or_b32:
|
|
|
|
|
case aco_opcode::s_xor_b32:
|
|
|
|
|
case aco_opcode::s_and_b64:
|
|
|
|
|
case aco_opcode::s_or_b64:
|
|
|
|
|
case aco_opcode::s_xor_b64: break;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create instruction */
|
|
|
|
|
std::swap(instr->definitions[0], op2_instr->definitions[0]);
|
2020-01-28 12:32:09 +01:00
|
|
|
std::swap(instr->definitions[1], op2_instr->definitions[1]);
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
|
|
|
|
ctx.info[op2_instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[op2_instr->definitions[0].tempId()].parent_instr = op2_instr;
|
|
|
|
|
ctx.info[op2_instr->definitions[1].tempId()].parent_instr = op2_instr;
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
switch (op2_instr->opcode) {
|
|
|
|
|
case aco_opcode::s_and_b32: op2_instr->opcode = aco_opcode::s_nand_b32; break;
|
|
|
|
|
case aco_opcode::s_or_b32: op2_instr->opcode = aco_opcode::s_nor_b32; break;
|
|
|
|
|
case aco_opcode::s_xor_b32: op2_instr->opcode = aco_opcode::s_xnor_b32; break;
|
|
|
|
|
case aco_opcode::s_and_b64: op2_instr->opcode = aco_opcode::s_nand_b64; break;
|
|
|
|
|
case aco_opcode::s_or_b64: op2_instr->opcode = aco_opcode::s_nor_b64; break;
|
|
|
|
|
case aco_opcode::s_xor_b64: op2_instr->opcode = aco_opcode::s_xnor_b64; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* s_and_b32(a, s_not_b32(b)) -> s_andn2_b32(a, b)
|
|
|
|
|
* s_or_b32(a, s_not_b32(b)) -> s_orn2_b32(a, b)
|
|
|
|
|
* s_and_b64(a, s_not_b64(b)) -> s_andn2_b64(a, b)
|
|
|
|
|
* s_or_b64(a, s_not_b64(b)) -> s_orn2_b64(a, b) */
|
|
|
|
|
bool
|
|
|
|
|
combine_salu_n2(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2020-02-05 11:19:06 +01:00
|
|
|
if (instr->definitions[0].isTemp() && ctx.info[instr->definitions[0].tempId()].is_uniform_bool())
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
Instruction* op2_instr = follow_operand(ctx, instr->operands[i]);
|
|
|
|
|
if (!op2_instr || (op2_instr->opcode != aco_opcode::s_not_b32 &&
|
|
|
|
|
op2_instr->opcode != aco_opcode::s_not_b64))
|
|
|
|
|
continue;
|
2022-09-28 14:37:19 +02:00
|
|
|
if (ctx.uses[op2_instr->definitions[1].tempId()])
|
2020-01-28 12:04:48 +00:00
|
|
|
continue;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-11-22 14:34:24 +00:00
|
|
|
if (instr->operands[!i].isLiteral() && op2_instr->operands[0].isLiteral() &&
|
|
|
|
|
instr->operands[!i].constantValue() != op2_instr->operands[0].constantValue())
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
instr->operands[0] = instr->operands[!i];
|
|
|
|
|
instr->operands[1] = op2_instr->operands[0];
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
|
|
|
|
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::s_and_b32: instr->opcode = aco_opcode::s_andn2_b32; break;
|
|
|
|
|
case aco_opcode::s_or_b32: instr->opcode = aco_opcode::s_orn2_b32; break;
|
|
|
|
|
case aco_opcode::s_and_b64: instr->opcode = aco_opcode::s_andn2_b64; break;
|
|
|
|
|
case aco_opcode::s_or_b64: instr->opcode = aco_opcode::s_orn2_b64; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* s_add_{i32,u32}(a, s_lshl_b32(b, <n>)) -> s_lshl<n>_add_u32(a, b) */
|
|
|
|
|
bool
|
|
|
|
|
combine_salu_lshl_add(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2020-01-28 12:05:26 +00:00
|
|
|
if (instr->opcode == aco_opcode::s_add_i32 && ctx.uses[instr->definitions[1].tempId()])
|
2019-09-17 13:22:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
aco: combine more s_add+s_lshl to s_lshl<n>_add by ignoring uses
Even if the s_lshl is used more that once, it can still be combined.
fossils-db (Vega10):
Totals from 771 (0.55% of 139517) affected shaders:
SGPRs: 46216 -> 46304 (+0.19%); split: -0.02%, +0.21%
VGPRs: 38488 -> 38464 (-0.06%)
SpillSGPRs: 1894 -> 1875 (-1.00%); split: -3.12%, +2.11%
CodeSize: 5681856 -> 5679844 (-0.04%); split: -0.07%, +0.03%
MaxWaves: 5320 -> 5323 (+0.06%)
Instrs: 1093960 -> 1093474 (-0.04%); split: -0.09%, +0.05%
Cycles: 47198380 -> 47258872 (+0.13%); split: -0.06%, +0.19%
VMEM: 176036 -> 176283 (+0.14%); split: +0.16%, -0.02%
SMEM: 53397 -> 53255 (-0.27%); split: +0.03%, -0.30%
VClause: 23156 -> 23152 (-0.02%); split: -0.03%, +0.01%
SClause: 35716 -> 35726 (+0.03%); split: -0.00%, +0.03%
Copies: 139395 -> 139871 (+0.34%); split: -0.04%, +0.39%
Branches: 33808 -> 33798 (-0.03%); split: -0.04%, +0.01%
PreSGPRs: 35381 -> 35331 (-0.14%); split: -0.20%, +0.06%
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7539>
2020-11-10 11:20:18 +01:00
|
|
|
Instruction* op2_instr = follow_operand(ctx, instr->operands[i], true);
|
2020-01-28 12:05:26 +00:00
|
|
|
if (!op2_instr || op2_instr->opcode != aco_opcode::s_lshl_b32 ||
|
|
|
|
|
ctx.uses[op2_instr->definitions[1].tempId()])
|
2020-01-28 12:04:48 +00:00
|
|
|
continue;
|
2022-09-28 14:37:19 +02:00
|
|
|
if (!op2_instr->operands[1].isConstant())
|
2019-09-17 13:22:17 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
uint32_t shift = op2_instr->operands[1].constantValue();
|
|
|
|
|
if (shift < 1 || shift > 4)
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-11-22 14:34:24 +00:00
|
|
|
if (instr->operands[!i].isLiteral() && op2_instr->operands[0].isLiteral() &&
|
|
|
|
|
instr->operands[!i].constantValue() != op2_instr->operands[0].constantValue())
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->operands[1] = instr->operands[!i];
|
2022-09-28 13:45:25 +02:00
|
|
|
instr->operands[0] = copy_operand(ctx, op2_instr->operands[0]);
|
2025-06-04 17:06:41 +02:00
|
|
|
decrease_and_dce(ctx, op2_instr->definitions[0].getTemp());
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
|
|
|
|
|
2020-11-26 22:03:27 -08:00
|
|
|
instr->opcode = std::array<aco_opcode, 4>{
|
|
|
|
|
aco_opcode::s_lshl1_add_u32, aco_opcode::s_lshl2_add_u32, aco_opcode::s_lshl3_add_u32,
|
|
|
|
|
aco_opcode::s_lshl4_add_u32}[shift - 1];
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-23 19:00:36 +02:00
|
|
|
/* s_abs_i32(s_sub_[iu]32(a, b)) -> s_absdiff_i32(a, b)
|
|
|
|
|
* s_abs_i32(s_add_[iu]32(a, #b)) -> s_absdiff_i32(a, -b)
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
combine_sabsdiff(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[0], false);
|
|
|
|
|
if (!op_instr)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (op_instr->opcode == aco_opcode::s_add_i32 || op_instr->opcode == aco_opcode::s_add_u32) {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
uint64_t constant;
|
|
|
|
|
if (op_instr->operands[!i].isLiteral() ||
|
|
|
|
|
!is_operand_constant(ctx, op_instr->operands[i], 32, &constant))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (op_instr->operands[i].isTemp())
|
|
|
|
|
ctx.uses[op_instr->operands[i].tempId()]--;
|
|
|
|
|
op_instr->operands[0] = op_instr->operands[!i];
|
|
|
|
|
op_instr->operands[1] = Operand::c32(-int32_t(constant));
|
|
|
|
|
goto use_absdiff;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-07-15 18:59:56 +02:00
|
|
|
} else if (op_instr->opcode != aco_opcode::s_sub_i32 &&
|
|
|
|
|
op_instr->opcode != aco_opcode::s_sub_u32) {
|
|
|
|
|
return false;
|
2022-09-23 19:00:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use_absdiff:
|
|
|
|
|
op_instr->opcode = aco_opcode::s_absdiff_i32;
|
|
|
|
|
std::swap(instr->definitions[0], op_instr->definitions[0]);
|
|
|
|
|
std::swap(instr->definitions[1], op_instr->definitions[1]);
|
|
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
2024-06-10 14:31:32 +01:00
|
|
|
ctx.info[op_instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[op_instr->definitions[0].tempId()].parent_instr = op_instr;
|
|
|
|
|
ctx.info[op_instr->definitions[1].tempId()].parent_instr = op_instr;
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].parent_instr = instr.get();
|
2022-09-23 19:00:36 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 17:41:36 +02:00
|
|
|
bool
|
|
|
|
|
combine_add_sub_b2i(opt_ctx& ctx, aco_ptr<Instruction>& instr, aco_opcode new_op, uint8_t ops)
|
|
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (!((1 << i) & ops))
|
|
|
|
|
continue;
|
|
|
|
|
if (instr->operands[i].isTemp() && ctx.info[instr->operands[i].tempId()].is_b2i() &&
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()] == 1) {
|
|
|
|
|
|
|
|
|
|
aco_ptr<Instruction> new_instr;
|
|
|
|
|
if (instr->operands[!i].isTemp() &&
|
|
|
|
|
instr->operands[!i].getTemp().type() == RegType::vgpr) {
|
2024-03-25 15:55:27 +01:00
|
|
|
new_instr.reset(create_instruction(new_op, Format::VOP2, 3, 2));
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (ctx.program->gfx_level >= GFX10 ||
|
2020-04-02 17:41:36 +02:00
|
|
|
(instr->operands[!i].isConstant() && !instr->operands[!i].isLiteral())) {
|
2024-03-25 15:55:27 +01:00
|
|
|
new_instr.reset(create_instruction(new_op, asVOP3(Format::VOP2), 3, 2));
|
2020-04-02 17:41:36 +02:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
aco: fix combining add/sub to b2i if a new dest needs to be allocated
The uses vector needs to be expanded to avoid out of bounds access
and to make sure the number of uses is initialized to 0.
This fixes combining more v_and(a, v_subbrev_co_u32).
fossilds-db (Vega10):
Totals from 4574 (3.28% of 139517) affected shaders:
SGPRs: 291625 -> 292217 (+0.20%); split: -0.01%, +0.21%
VGPRs: 276368 -> 276188 (-0.07%); split: -0.07%, +0.01%
SpillSGPRs: 455 -> 533 (+17.14%)
SpillVGPRs: 76 -> 78 (+2.63%)
CodeSize: 23327500 -> 23304152 (-0.10%); split: -0.17%, +0.07%
MaxWaves: 22044 -> 22066 (+0.10%)
Instrs: 4583064 -> 4576301 (-0.15%); split: -0.15%, +0.01%
Cycles: 47925276 -> 47871968 (-0.11%); split: -0.13%, +0.01%
VMEM: 1599363 -> 1597473 (-0.12%); split: +0.08%, -0.19%
SMEM: 331461 -> 331126 (-0.10%); split: +0.08%, -0.18%
VClause: 80639 -> 80696 (+0.07%); split: -0.02%, +0.09%
SClause: 155992 -> 155993 (+0.00%); split: -0.02%, +0.02%
Copies: 333482 -> 333318 (-0.05%); split: -0.12%, +0.07%
Branches: 70967 -> 70968 (+0.00%)
PreSGPRs: 187078 -> 187711 (+0.34%); split: -0.01%, +0.35%
PreVGPRs: 244918 -> 244785 (-0.05%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7513>
2020-11-09 19:42:22 +01:00
|
|
|
if (instr->definitions.size() == 2) {
|
|
|
|
|
new_instr->definitions[1] = instr->definitions[1];
|
|
|
|
|
} else {
|
|
|
|
|
new_instr->definitions[1] =
|
|
|
|
|
Definition(ctx.program->allocateTmp(ctx.program->lane_mask));
|
|
|
|
|
/* Make sure the uses vector is large enough and the number of
|
|
|
|
|
* uses properly initialized to 0.
|
|
|
|
|
*/
|
|
|
|
|
ctx.uses.push_back(0);
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
ctx.info.push_back(ssa_info{});
|
aco: fix combining add/sub to b2i if a new dest needs to be allocated
The uses vector needs to be expanded to avoid out of bounds access
and to make sure the number of uses is initialized to 0.
This fixes combining more v_and(a, v_subbrev_co_u32).
fossilds-db (Vega10):
Totals from 4574 (3.28% of 139517) affected shaders:
SGPRs: 291625 -> 292217 (+0.20%); split: -0.01%, +0.21%
VGPRs: 276368 -> 276188 (-0.07%); split: -0.07%, +0.01%
SpillSGPRs: 455 -> 533 (+17.14%)
SpillVGPRs: 76 -> 78 (+2.63%)
CodeSize: 23327500 -> 23304152 (-0.10%); split: -0.17%, +0.07%
MaxWaves: 22044 -> 22066 (+0.10%)
Instrs: 4583064 -> 4576301 (-0.15%); split: -0.15%, +0.01%
Cycles: 47925276 -> 47871968 (-0.11%); split: -0.13%, +0.01%
VMEM: 1599363 -> 1597473 (-0.12%); split: +0.08%, -0.19%
SMEM: 331461 -> 331126 (-0.10%); split: +0.08%, -0.18%
VClause: 80639 -> 80696 (+0.07%); split: -0.02%, +0.09%
SClause: 155992 -> 155993 (+0.00%); split: -0.02%, +0.02%
Copies: 333482 -> 333318 (-0.05%); split: -0.12%, +0.07%
Branches: 70967 -> 70968 (+0.00%)
PreSGPRs: 187078 -> 187711 (+0.34%); split: -0.01%, +0.35%
PreVGPRs: 244918 -> 244785 (-0.05%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7513>
2020-11-09 19:42:22 +01:00
|
|
|
}
|
2021-07-13 11:22:46 +02:00
|
|
|
new_instr->operands[0] = Operand::zero();
|
2020-04-02 17:41:36 +02:00
|
|
|
new_instr->operands[1] = instr->operands[!i];
|
|
|
|
|
new_instr->operands[2] = Operand(ctx.info[instr->operands[i].tempId()].temp);
|
2023-05-09 20:24:52 +02:00
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
2020-04-02 17:41:36 +02:00
|
|
|
instr = std::move(new_instr);
|
2024-07-30 11:31:15 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[1].tempId()].parent_instr = instr.get();
|
2020-04-02 17:41:36 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 18:42:35 +01:00
|
|
|
bool
|
|
|
|
|
combine_add_bcnt(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[i]);
|
|
|
|
|
if (op_instr && op_instr->opcode == aco_opcode::v_bcnt_u32_b32 &&
|
2021-09-28 17:11:28 +01:00
|
|
|
!op_instr->usesModifiers() && op_instr->operands[0].isTemp() &&
|
2020-11-11 18:42:35 +01:00
|
|
|
op_instr->operands[0].getTemp().type() == RegType::vgpr &&
|
|
|
|
|
op_instr->operands[1].constantEquals(0)) {
|
2021-01-20 13:50:45 +00:00
|
|
|
aco_ptr<Instruction> new_instr{
|
2024-03-25 15:55:27 +01:00
|
|
|
create_instruction(aco_opcode::v_bcnt_u32_b32, Format::VOP3, 2, 1)};
|
2020-11-11 18:42:35 +01:00
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
new_instr->operands[0] = op_instr->operands[0];
|
|
|
|
|
new_instr->operands[1] = instr->operands[!i];
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
2023-05-09 20:24:52 +02:00
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
2020-11-11 18:42:35 +01:00
|
|
|
instr = std::move(new_instr);
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2020-11-11 18:42:35 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
bool
|
|
|
|
|
get_minmax_info(aco_opcode op, aco_opcode* min, aco_opcode* max, aco_opcode* min3, aco_opcode* max3,
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
aco_opcode* med3, aco_opcode* minmax, bool* some_gfx9_only)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
switch (op) {
|
|
|
|
|
#define MINMAX(type, gfx9) \
|
|
|
|
|
case aco_opcode::v_min_##type: \
|
|
|
|
|
case aco_opcode::v_max_##type: \
|
|
|
|
|
*min = aco_opcode::v_min_##type; \
|
|
|
|
|
*max = aco_opcode::v_max_##type; \
|
|
|
|
|
*med3 = aco_opcode::v_med3_##type; \
|
|
|
|
|
*min3 = aco_opcode::v_min3_##type; \
|
|
|
|
|
*max3 = aco_opcode::v_max3_##type; \
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
*minmax = op == *min ? aco_opcode::v_maxmin_##type : aco_opcode::v_minmax_##type; \
|
|
|
|
|
*some_gfx9_only = gfx9; \
|
|
|
|
|
return true;
|
|
|
|
|
#define MINMAX_INT16(type, gfx9) \
|
|
|
|
|
case aco_opcode::v_min_##type: \
|
|
|
|
|
case aco_opcode::v_max_##type: \
|
|
|
|
|
*min = aco_opcode::v_min_##type; \
|
|
|
|
|
*max = aco_opcode::v_max_##type; \
|
|
|
|
|
*med3 = aco_opcode::v_med3_##type; \
|
|
|
|
|
*min3 = aco_opcode::v_min3_##type; \
|
|
|
|
|
*max3 = aco_opcode::v_max3_##type; \
|
|
|
|
|
*minmax = aco_opcode::num_opcodes; \
|
2019-09-17 13:22:17 +02:00
|
|
|
*some_gfx9_only = gfx9; \
|
|
|
|
|
return true;
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
#define MINMAX_INT16_E64(type, gfx9) \
|
2022-04-29 17:19:09 +01:00
|
|
|
case aco_opcode::v_min_##type##_e64: \
|
|
|
|
|
case aco_opcode::v_max_##type##_e64: \
|
|
|
|
|
*min = aco_opcode::v_min_##type##_e64; \
|
|
|
|
|
*max = aco_opcode::v_max_##type##_e64; \
|
|
|
|
|
*med3 = aco_opcode::v_med3_##type; \
|
|
|
|
|
*min3 = aco_opcode::v_min3_##type; \
|
|
|
|
|
*max3 = aco_opcode::v_max3_##type; \
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
*minmax = aco_opcode::num_opcodes; \
|
2022-04-29 17:19:09 +01:00
|
|
|
*some_gfx9_only = gfx9; \
|
|
|
|
|
return true;
|
2019-09-17 13:22:17 +02:00
|
|
|
MINMAX(f32, false)
|
|
|
|
|
MINMAX(u32, false)
|
|
|
|
|
MINMAX(i32, false)
|
|
|
|
|
MINMAX(f16, true)
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
MINMAX_INT16(u16, true)
|
|
|
|
|
MINMAX_INT16(i16, true)
|
|
|
|
|
MINMAX_INT16_E64(u16, true)
|
|
|
|
|
MINMAX_INT16_E64(i16, true)
|
|
|
|
|
#undef MINMAX_INT16_E64
|
|
|
|
|
#undef MINMAX_INT16
|
2019-09-17 13:22:17 +02:00
|
|
|
#undef MINMAX
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* when ub > lb:
|
|
|
|
|
* v_min_{f,u,i}{16,32}(v_max_{f,u,i}{16,32}(a, lb), ub) -> v_med3_{f,u,i}{16,32}(a, lb, ub)
|
|
|
|
|
* v_max_{f,u,i}{16,32}(v_min_{f,u,i}{16,32}(a, ub), lb) -> v_med3_{f,u,i}{16,32}(a, lb, ub)
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
combine_clamp(opt_ctx& ctx, aco_ptr<Instruction>& instr, aco_opcode min, aco_opcode max,
|
|
|
|
|
aco_opcode med)
|
|
|
|
|
{
|
2019-11-22 17:50:29 +00:00
|
|
|
/* TODO: GLSL's clamp(x, minVal, maxVal) and SPIR-V's
|
|
|
|
|
* FClamp(x, minVal, maxVal)/NClamp(x, minVal, maxVal) are undefined if
|
|
|
|
|
* minVal > maxVal, which means we can always select it to a v_med3_f32 */
|
2019-09-17 13:22:17 +02:00
|
|
|
aco_opcode other_op;
|
|
|
|
|
if (instr->opcode == min)
|
|
|
|
|
other_op = max;
|
|
|
|
|
else if (instr->opcode == max)
|
|
|
|
|
other_op = min;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned swap = 0; swap < 2; swap++) {
|
|
|
|
|
Operand operands[3];
|
2023-03-08 16:30:39 +01:00
|
|
|
bool clamp, precise;
|
|
|
|
|
bitarray8 opsel = 0, neg = 0, abs = 0;
|
|
|
|
|
uint8_t omod = 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
if (match_op3_for_vop3(ctx, instr->opcode, other_op, instr.get(), swap, "012", operands, neg,
|
2023-03-08 16:30:39 +01:00
|
|
|
abs, opsel, &clamp, &omod, NULL, NULL, NULL, &precise)) {
|
2020-10-07 11:09:16 +01:00
|
|
|
/* max(min(src, upper), lower) returns upper if src is NaN, but
|
|
|
|
|
* med3(src, lower, upper) returns lower.
|
|
|
|
|
*/
|
2022-04-29 17:23:20 +01:00
|
|
|
if (precise && instr->opcode != min &&
|
|
|
|
|
(min == aco_opcode::v_min_f16 || min == aco_opcode::v_min_f32))
|
2020-10-07 11:09:16 +01:00
|
|
|
continue;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
int const0_idx = -1, const1_idx = -1;
|
|
|
|
|
uint32_t const0 = 0, const1 = 0;
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
uint32_t val;
|
2022-04-29 16:45:17 +01:00
|
|
|
bool hi16 = opsel & (1 << i);
|
2019-09-17 13:22:17 +02:00
|
|
|
if (operands[i].isConstant()) {
|
2022-04-29 16:45:17 +01:00
|
|
|
val = hi16 ? operands[i].constantValue16(true) : operands[i].constantValue();
|
2020-05-15 16:28:03 +01:00
|
|
|
} else if (operands[i].isTemp() &&
|
|
|
|
|
ctx.info[operands[i].tempId()].is_constant_or_literal(32)) {
|
2022-04-29 16:45:17 +01:00
|
|
|
val = ctx.info[operands[i].tempId()].val >> (hi16 ? 16 : 0);
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (const0_idx >= 0) {
|
|
|
|
|
const1_idx = i;
|
|
|
|
|
const1 = val;
|
|
|
|
|
} else {
|
|
|
|
|
const0_idx = i;
|
|
|
|
|
const0 = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (const0_idx < 0 || const1_idx < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
int lower_idx = const0_idx;
|
|
|
|
|
switch (min) {
|
|
|
|
|
case aco_opcode::v_min_f32:
|
|
|
|
|
case aco_opcode::v_min_f16: {
|
|
|
|
|
float const0_f, const1_f;
|
|
|
|
|
if (min == aco_opcode::v_min_f32) {
|
|
|
|
|
memcpy(&const0_f, &const0, 4);
|
|
|
|
|
memcpy(&const1_f, &const1, 4);
|
|
|
|
|
} else {
|
|
|
|
|
const0_f = _mesa_half_to_float(const0);
|
|
|
|
|
const1_f = _mesa_half_to_float(const1);
|
|
|
|
|
}
|
|
|
|
|
if (abs[const0_idx])
|
|
|
|
|
const0_f = fabsf(const0_f);
|
|
|
|
|
if (abs[const1_idx])
|
|
|
|
|
const1_f = fabsf(const1_f);
|
|
|
|
|
if (neg[const0_idx])
|
|
|
|
|
const0_f = -const0_f;
|
|
|
|
|
if (neg[const1_idx])
|
|
|
|
|
const1_f = -const1_f;
|
|
|
|
|
lower_idx = const0_f < const1_f ? const0_idx : const1_idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::v_min_u32: {
|
|
|
|
|
lower_idx = const0 < const1 ? const0_idx : const1_idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-04-29 17:19:09 +01:00
|
|
|
case aco_opcode::v_min_u16:
|
|
|
|
|
case aco_opcode::v_min_u16_e64: {
|
2019-09-17 13:22:17 +02:00
|
|
|
lower_idx = (uint16_t)const0 < (uint16_t)const1 ? const0_idx : const1_idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case aco_opcode::v_min_i32: {
|
|
|
|
|
int32_t const0_i =
|
|
|
|
|
const0 & 0x80000000u ? -2147483648 + (int32_t)(const0 & 0x7fffffffu) : const0;
|
|
|
|
|
int32_t const1_i =
|
|
|
|
|
const1 & 0x80000000u ? -2147483648 + (int32_t)(const1 & 0x7fffffffu) : const1;
|
|
|
|
|
lower_idx = const0_i < const1_i ? const0_idx : const1_idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-04-29 17:19:09 +01:00
|
|
|
case aco_opcode::v_min_i16:
|
|
|
|
|
case aco_opcode::v_min_i16_e64: {
|
2019-09-17 13:22:17 +02:00
|
|
|
int16_t const0_i = const0 & 0x8000u ? -32768 + (int16_t)(const0 & 0x7fffu) : const0;
|
|
|
|
|
int16_t const1_i = const1 & 0x8000u ? -32768 + (int16_t)(const1 & 0x7fffu) : const1;
|
|
|
|
|
lower_idx = const0_i < const1_i ? const0_idx : const1_idx;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
int upper_idx = lower_idx == const0_idx ? const1_idx : const0_idx;
|
|
|
|
|
|
|
|
|
|
if (instr->opcode == min) {
|
|
|
|
|
if (upper_idx != 0 || lower_idx == 0)
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if (upper_idx == 0 || lower_idx != 0)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.uses[instr->operands[swap].tempId()]--;
|
|
|
|
|
create_vop3_for_op3(ctx, med, instr, operands, neg, abs, opsel, clamp, omod);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 15:02:45 +01:00
|
|
|
bool
|
|
|
|
|
interp_can_become_fma(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->opcode != aco_opcode::v_interp_p2_f32_inreg)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
instr->opcode = aco_opcode::v_fma_f32;
|
|
|
|
|
instr->format = Format::VOP3;
|
|
|
|
|
bool dpp_allowed = can_use_DPP(ctx.program->gfx_level, instr, false);
|
|
|
|
|
instr->opcode = aco_opcode::v_interp_p2_f32_inreg;
|
|
|
|
|
instr->format = Format::VINTERP_INREG;
|
|
|
|
|
|
|
|
|
|
return dpp_allowed;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 13:01:09 +02:00
|
|
|
void
|
|
|
|
|
interp_p2_f32_inreg_to_fma_dpp(aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
static_assert(sizeof(DPP16_instruction) == sizeof(VINTERP_inreg_instruction),
|
|
|
|
|
"Invalid instr cast.");
|
|
|
|
|
instr->format = asVOP3(Format::DPP16);
|
|
|
|
|
instr->opcode = aco_opcode::v_fma_f32;
|
|
|
|
|
instr->dpp16().dpp_ctrl = dpp_quad_perm(2, 2, 2, 2);
|
|
|
|
|
instr->dpp16().row_mask = 0xf;
|
|
|
|
|
instr->dpp16().bank_mask = 0xf;
|
|
|
|
|
instr->dpp16().bound_ctrl = 0;
|
|
|
|
|
instr->dpp16().fetch_inactive = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
/* apply omod / clamp modifiers if the def is used only once and the instruction can have modifiers */
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
bool
|
|
|
|
|
apply_omod_clamp(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
2020-08-12 15:58:32 +01:00
|
|
|
{
|
|
|
|
|
if (instr->definitions.empty() || ctx.uses[instr->definitions[0].tempId()] != 1 ||
|
2025-04-29 15:55:47 +02:00
|
|
|
!instr_info.alu_opcode_infos[(int)instr->opcode].output_modifiers)
|
2020-08-12 15:58:32 +01:00
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-12-05 14:12:39 +00:00
|
|
|
bool can_vop3 = can_use_VOP3(ctx, instr);
|
2022-01-17 17:54:47 +00:00
|
|
|
bool is_mad_mix =
|
|
|
|
|
instr->opcode == aco_opcode::v_fma_mix_f32 || instr->opcode == aco_opcode::v_fma_mixlo_f16;
|
2023-09-14 13:01:09 +02:00
|
|
|
bool needs_vop3 = !instr->isSDWA() && !instr->isVINTERP_INREG() && !is_mad_mix;
|
|
|
|
|
if (needs_vop3 && !can_vop3)
|
2020-08-12 15:58:32 +01:00
|
|
|
return false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2025-03-12 14:15:17 +01:00
|
|
|
if (instr_info.classes[(int)instr->opcode] == instr_class::valu_pseudo_scalar_trans)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-09-22 14:10:52 +02:00
|
|
|
/* SDWA omod is GFX9+. */
|
2024-08-01 15:02:45 +01:00
|
|
|
bool can_use_omod = (can_vop3 || ctx.program->gfx_level >= GFX9) && !instr->isVOP3P() &&
|
|
|
|
|
(!instr->isVINTERP_INREG() || interp_can_become_fma(ctx, instr));
|
2019-12-05 14:12:39 +00:00
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
ssa_info& def_info = ctx.info[instr->definitions[0].tempId()];
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
uint64_t omod_labels = label_omod2 | label_omod4 | label_omod5;
|
|
|
|
|
if (!def_info.is_clamp() && !(can_use_omod && (def_info.label & omod_labels)))
|
|
|
|
|
return false;
|
|
|
|
|
/* if the omod/clamp instruction is dead, then the single user of this
|
|
|
|
|
* instruction is a different instruction */
|
2024-07-23 17:49:32 +02:00
|
|
|
if (!ctx.uses[def_info.mod_instr->definitions[0].tempId()])
|
2020-08-12 15:58:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
if (def_info.mod_instr->definitions[0].bytes() != instr->definitions[0].bytes())
|
2022-01-31 18:12:59 +00:00
|
|
|
return false;
|
|
|
|
|
|
2020-08-12 15:58:32 +01:00
|
|
|
/* MADs/FMAs are created later, so we don't have to update the original add */
|
|
|
|
|
assert(!ctx.info[instr->definitions[0].tempId()].is_mad());
|
|
|
|
|
|
2023-01-31 18:03:01 +01:00
|
|
|
if (!def_info.is_clamp() && (instr->valu().clamp || instr->valu().omod))
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-09-14 13:01:09 +02:00
|
|
|
if (needs_vop3)
|
|
|
|
|
instr->format = asVOP3(instr->format);
|
|
|
|
|
|
|
|
|
|
if (!def_info.is_clamp() && instr->opcode == aco_opcode::v_interp_p2_f32_inreg)
|
|
|
|
|
interp_p2_f32_inreg_to_fma_dpp(instr);
|
|
|
|
|
|
2023-01-31 18:03:01 +01:00
|
|
|
if (def_info.is_omod2())
|
|
|
|
|
instr->valu().omod = 1;
|
|
|
|
|
else if (def_info.is_omod4())
|
|
|
|
|
instr->valu().omod = 2;
|
|
|
|
|
else if (def_info.is_omod5())
|
|
|
|
|
instr->valu().omod = 3;
|
|
|
|
|
else if (def_info.is_clamp())
|
|
|
|
|
instr->valu().clamp = true;
|
2020-08-12 15:58:32 +01:00
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
instr->definitions[0].swapTemp(def_info.mod_instr->definitions[0]);
|
2022-01-17 16:52:10 +00:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label &= label_clamp | label_insert | label_f2f16;
|
2024-07-23 17:49:32 +02:00
|
|
|
ctx.uses[def_info.mod_instr->definitions[0].tempId()]--;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[def_info.mod_instr->definitions[0].tempId()].parent_instr = def_info.mod_instr;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Combine an p_insert (or p_extract, in some cases) instruction with instr.
|
|
|
|
|
* p_insert(instr(...)) -> instr_insert().
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
apply_insert(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->definitions.empty() || ctx.uses[instr->definitions[0].tempId()] != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ssa_info& def_info = ctx.info[instr->definitions[0].tempId()];
|
|
|
|
|
if (!def_info.is_insert())
|
|
|
|
|
return false;
|
|
|
|
|
/* if the insert instruction is dead, then the single user of this
|
|
|
|
|
* instruction is a different instruction */
|
2024-07-23 17:49:32 +02:00
|
|
|
if (!ctx.uses[def_info.mod_instr->definitions[0].tempId()])
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* MADs/FMAs are created later, so we don't have to update the original add */
|
|
|
|
|
assert(!ctx.info[instr->definitions[0].tempId()].is_mad());
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
SubdwordSel sel = parse_insert(def_info.mod_instr);
|
2021-08-30 17:58:36 +02:00
|
|
|
assert(sel);
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
2023-01-21 17:08:03 +01:00
|
|
|
if (!can_use_SDWA(ctx.program->gfx_level, instr, true))
|
|
|
|
|
return false;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
2023-03-22 19:58:28 +01:00
|
|
|
convert_to_SDWA(ctx.program->gfx_level, instr);
|
2023-01-21 17:08:03 +01:00
|
|
|
if (instr->sdwa().dst_sel.size() != 4)
|
|
|
|
|
return false;
|
2023-03-22 19:58:28 +01:00
|
|
|
instr->sdwa().dst_sel = sel;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
instr->definitions[0].swapTemp(def_info.mod_instr->definitions[0]);
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-23 17:49:32 +02:00
|
|
|
ctx.uses[def_info.mod_instr->definitions[0].tempId()]--;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
|
|
|
|
ctx.info[def_info.mod_instr->definitions[0].tempId()].parent_instr = def_info.mod_instr;
|
|
|
|
|
for (const Definition& def : instr->definitions)
|
|
|
|
|
ctx.info[def.tempId()].parent_instr = instr.get();
|
2020-08-12 15:58:32 +01:00
|
|
|
|
|
|
|
|
return true;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-27 15:45:59 +02:00
|
|
|
/* Remove superfluous extract after ds_read like so:
|
|
|
|
|
* p_extract(ds_read_uN(), 0, N, 0) -> ds_read_uN()
|
|
|
|
|
*/
|
|
|
|
|
bool
|
2025-03-11 15:18:39 +00:00
|
|
|
apply_load_extract(opt_ctx& ctx, aco_ptr<Instruction>& extract)
|
2021-08-27 15:45:59 +02:00
|
|
|
{
|
|
|
|
|
/* Check if p_extract has a usedef operand and is the only user. */
|
2024-07-30 11:31:15 +02:00
|
|
|
if (ctx.uses[extract->operands[0].tempId()] > 1)
|
2021-08-27 15:45:59 +02:00
|
|
|
return false;
|
|
|
|
|
|
2025-03-11 15:18:39 +00:00
|
|
|
/* Check if the usedef is the right format. */
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* load = ctx.info[extract->operands[0].tempId()].parent_instr;
|
2025-03-11 15:18:39 +00:00
|
|
|
if (!load->isDS() && !load->isSMEM() && !load->isMUBUF() && !load->isFlatLike())
|
2021-08-27 15:45:59 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
unsigned extract_idx = extract->operands[1].constantValue();
|
|
|
|
|
unsigned bits_extracted = extract->operands[2].constantValue();
|
2025-03-11 15:43:49 +00:00
|
|
|
bool sign_ext = extract->operands[3].constantValue();
|
2021-08-27 15:45:59 +02:00
|
|
|
unsigned dst_bitsize = extract->definitions[0].bytes() * 8u;
|
|
|
|
|
|
|
|
|
|
unsigned bits_loaded = 0;
|
2025-03-11 15:18:39 +00:00
|
|
|
bool can_shrink = false;
|
|
|
|
|
switch (load->opcode) {
|
|
|
|
|
case aco_opcode::ds_read_u8:
|
|
|
|
|
case aco_opcode::ds_read_u8_d16:
|
|
|
|
|
case aco_opcode::flat_load_ubyte:
|
|
|
|
|
case aco_opcode::flat_load_ubyte_d16:
|
|
|
|
|
case aco_opcode::global_load_ubyte:
|
|
|
|
|
case aco_opcode::global_load_ubyte_d16:
|
|
|
|
|
case aco_opcode::scratch_load_ubyte:
|
|
|
|
|
case aco_opcode::scratch_load_ubyte_d16: can_shrink = true; FALLTHROUGH;
|
|
|
|
|
case aco_opcode::s_load_ubyte:
|
|
|
|
|
case aco_opcode::s_buffer_load_ubyte:
|
|
|
|
|
case aco_opcode::buffer_load_ubyte:
|
|
|
|
|
case aco_opcode::buffer_load_ubyte_d16: bits_loaded = 8; break;
|
|
|
|
|
case aco_opcode::ds_read_u16:
|
|
|
|
|
case aco_opcode::ds_read_u16_d16:
|
|
|
|
|
case aco_opcode::flat_load_ushort:
|
|
|
|
|
case aco_opcode::flat_load_short_d16:
|
|
|
|
|
case aco_opcode::global_load_ushort:
|
|
|
|
|
case aco_opcode::global_load_short_d16:
|
|
|
|
|
case aco_opcode::scratch_load_ushort:
|
|
|
|
|
case aco_opcode::scratch_load_short_d16: can_shrink = true; FALLTHROUGH;
|
|
|
|
|
case aco_opcode::s_load_ushort:
|
|
|
|
|
case aco_opcode::s_buffer_load_ushort:
|
|
|
|
|
case aco_opcode::buffer_load_ushort:
|
|
|
|
|
case aco_opcode::buffer_load_short_d16: bits_loaded = 16; break;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 15:43:49 +00:00
|
|
|
/* TODO: These are doable, but probably don't occur too often. */
|
2025-03-25 15:53:07 +00:00
|
|
|
if (extract_idx || bits_extracted > bits_loaded || dst_bitsize > 32 ||
|
2025-03-11 15:43:49 +00:00
|
|
|
(load->definitions[0].regClass().type() != extract->definitions[0].regClass().type()))
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-03-11 15:18:39 +00:00
|
|
|
/* We can't shrink some loads because that would remove zeroing of the offset/address LSBs. */
|
|
|
|
|
if (!can_shrink && bits_extracted < bits_loaded)
|
2021-08-27 15:45:59 +02:00
|
|
|
return false;
|
|
|
|
|
|
2025-03-11 15:18:39 +00:00
|
|
|
/* Shrink the load if the extracted bit size is smaller. */
|
2021-08-27 15:45:59 +02:00
|
|
|
bits_loaded = MIN2(bits_loaded, bits_extracted);
|
|
|
|
|
|
2025-03-11 15:18:39 +00:00
|
|
|
/* Change the opcode so it writes the full register. */
|
2025-03-11 15:43:49 +00:00
|
|
|
bool is_s_buffer = load->opcode == aco_opcode::s_buffer_load_ubyte ||
|
|
|
|
|
load->opcode == aco_opcode::s_buffer_load_ushort;
|
2025-03-11 15:18:39 +00:00
|
|
|
if (bits_loaded == 8 && load->isDS())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::ds_read_i8 : aco_opcode::ds_read_u8;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 16 && load->isDS())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::ds_read_i16 : aco_opcode::ds_read_u16;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 8 && load->isMUBUF())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::buffer_load_sbyte : aco_opcode::buffer_load_ubyte;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 16 && load->isMUBUF())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::buffer_load_sshort : aco_opcode::buffer_load_ushort;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 8 && load->isFlat())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::flat_load_sbyte : aco_opcode::flat_load_ubyte;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 16 && load->isFlat())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::flat_load_sshort : aco_opcode::flat_load_ushort;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 8 && load->isGlobal())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::global_load_sbyte : aco_opcode::global_load_ubyte;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 16 && load->isGlobal())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::global_load_sshort : aco_opcode::global_load_ushort;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 8 && load->isScratch())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::scratch_load_sbyte : aco_opcode::scratch_load_ubyte;
|
2025-03-11 15:18:39 +00:00
|
|
|
else if (bits_loaded == 16 && load->isScratch())
|
2025-03-11 15:43:49 +00:00
|
|
|
load->opcode = sign_ext ? aco_opcode::scratch_load_sshort : aco_opcode::scratch_load_ushort;
|
|
|
|
|
else if (bits_loaded == 8 && load->isSMEM() && is_s_buffer)
|
|
|
|
|
load->opcode = sign_ext ? aco_opcode::s_buffer_load_sbyte : aco_opcode::s_buffer_load_ubyte;
|
|
|
|
|
else if (bits_loaded == 8 && load->isSMEM() && !is_s_buffer)
|
|
|
|
|
load->opcode = sign_ext ? aco_opcode::s_load_sbyte : aco_opcode::s_load_ubyte;
|
|
|
|
|
else if (bits_loaded == 16 && load->isSMEM() && is_s_buffer)
|
|
|
|
|
load->opcode = sign_ext ? aco_opcode::s_buffer_load_sshort : aco_opcode::s_buffer_load_ushort;
|
|
|
|
|
else if (bits_loaded == 16 && load->isSMEM() && !is_s_buffer)
|
|
|
|
|
load->opcode = sign_ext ? aco_opcode::s_load_sshort : aco_opcode::s_load_ushort;
|
|
|
|
|
else
|
2025-07-23 09:17:35 +02:00
|
|
|
UNREACHABLE("Forgot to add opcode above.");
|
2025-03-11 15:18:39 +00:00
|
|
|
|
|
|
|
|
if (dst_bitsize <= 16 && ctx.program->gfx_level >= GFX9) {
|
|
|
|
|
switch (load->opcode) {
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::ds_read_i8: load->opcode = aco_opcode::ds_read_i8_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::ds_read_u8: load->opcode = aco_opcode::ds_read_u8_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::ds_read_i16: load->opcode = aco_opcode::ds_read_u16_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::ds_read_u16: load->opcode = aco_opcode::ds_read_u16_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::buffer_load_sbyte: load->opcode = aco_opcode::buffer_load_sbyte_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::buffer_load_ubyte: load->opcode = aco_opcode::buffer_load_ubyte_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::buffer_load_sshort: load->opcode = aco_opcode::buffer_load_short_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::buffer_load_ushort: load->opcode = aco_opcode::buffer_load_short_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::flat_load_sbyte: load->opcode = aco_opcode::flat_load_sbyte_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::flat_load_ubyte: load->opcode = aco_opcode::flat_load_ubyte_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::flat_load_sshort: load->opcode = aco_opcode::flat_load_short_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::flat_load_ushort: load->opcode = aco_opcode::flat_load_short_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::global_load_sbyte: load->opcode = aco_opcode::global_load_sbyte_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::global_load_ubyte: load->opcode = aco_opcode::global_load_ubyte_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::global_load_sshort: load->opcode = aco_opcode::global_load_short_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::global_load_ushort: load->opcode = aco_opcode::global_load_short_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::scratch_load_sbyte: load->opcode = aco_opcode::scratch_load_sbyte_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::scratch_load_ubyte: load->opcode = aco_opcode::scratch_load_ubyte_d16; break;
|
2025-03-11 15:43:49 +00:00
|
|
|
case aco_opcode::scratch_load_sshort: load->opcode = aco_opcode::scratch_load_short_d16; break;
|
2025-03-11 15:18:39 +00:00
|
|
|
case aco_opcode::scratch_load_ushort: load->opcode = aco_opcode::scratch_load_short_d16; break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-27 15:45:59 +02:00
|
|
|
|
2025-03-11 15:18:39 +00:00
|
|
|
/* The load now produces the exact same thing as the extract, remove the extract. */
|
|
|
|
|
std::swap(load->definitions[0], extract->definitions[0]);
|
2021-08-27 15:45:59 +02:00
|
|
|
ctx.uses[extract->definitions[0].tempId()] = 0;
|
2025-03-11 15:18:39 +00:00
|
|
|
ctx.info[load->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[extract->definitions[0].tempId()].parent_instr = extract.get();
|
|
|
|
|
ctx.info[load->definitions[0].tempId()].parent_instr = load;
|
2021-08-27 15:45:59 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 20:55:58 +02:00
|
|
|
/* v_and(a, not(b)) -> v_bfi_b32(b, 0, a)
|
|
|
|
|
* v_or(a, not(b)) -> v_bfi_b32(b, a, -1)
|
|
|
|
|
*/
|
2023-07-29 18:47:04 +02:00
|
|
|
bool
|
2023-08-04 20:55:58 +02:00
|
|
|
combine_v_andor_not(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
2023-07-29 18:47:04 +02:00
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[i], true);
|
|
|
|
|
if (op_instr && !op_instr->usesModifiers() &&
|
|
|
|
|
(op_instr->opcode == aco_opcode::v_not_b32 ||
|
|
|
|
|
op_instr->opcode == aco_opcode::s_not_b32)) {
|
|
|
|
|
|
|
|
|
|
Operand ops[3] = {
|
|
|
|
|
op_instr->operands[0],
|
|
|
|
|
Operand::zero(),
|
|
|
|
|
instr->operands[!i],
|
|
|
|
|
};
|
2023-08-04 20:55:58 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_or_b32) {
|
|
|
|
|
ops[1] = instr->operands[!i];
|
|
|
|
|
ops[2] = Operand::c32(-1);
|
|
|
|
|
}
|
2023-07-29 18:47:04 +02:00
|
|
|
if (!check_vop3_operands(ctx, 3, ops))
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-03-25 15:55:27 +01:00
|
|
|
Instruction* new_instr = create_instruction(aco_opcode::v_bfi_b32, Format::VOP3, 3, 1);
|
2023-07-29 18:47:04 +02:00
|
|
|
|
2023-08-04 20:55:58 +02:00
|
|
|
if (op_instr->operands[0].isTemp())
|
|
|
|
|
ctx.uses[op_instr->operands[0].tempId()]++;
|
|
|
|
|
for (unsigned j = 0; j < 3; j++)
|
|
|
|
|
new_instr->operands[j] = ops[j];
|
2023-07-29 18:47:04 +02:00
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
|
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
|
|
|
|
instr.reset(new_instr);
|
2025-06-04 17:06:41 +02:00
|
|
|
decrease_and_dce(ctx, op_instr->definitions[0].getTemp());
|
2023-07-29 18:47:04 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2023-07-29 18:47:04 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 13:07:57 +01:00
|
|
|
/* v_add_co(c, s_lshl(a, b)) -> v_mad_u32_u24(a, 1<<b, c)
|
2021-09-09 08:38:41 +02:00
|
|
|
* v_add_co(c, v_lshlrev(a, b)) -> v_mad_u32_u24(b, 1<<a, c)
|
|
|
|
|
* v_sub(c, s_lshl(a, b)) -> v_mad_i32_i24(a, -(1<<b), c)
|
|
|
|
|
* v_sub(c, v_lshlrev(a, b)) -> v_mad_i32_i24(b, -(1<<a), c)
|
|
|
|
|
*/
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
bool
|
2021-09-09 08:38:41 +02:00
|
|
|
combine_add_lshl(opt_ctx& ctx, aco_ptr<Instruction>& instr, bool is_sub)
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
{
|
|
|
|
|
if (instr->usesModifiers())
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-09 08:38:41 +02:00
|
|
|
/* Substractions: start at operand 1 to avoid mixup such as
|
|
|
|
|
* turning v_sub(v_lshlrev(a, b), c) into v_mad_i32_i24(b, -(1<<a), c)
|
|
|
|
|
*/
|
|
|
|
|
unsigned start_op_idx = is_sub ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
/* Don't allow 24-bit operands on subtraction because
|
|
|
|
|
* v_mad_i32_i24 applies a sign extension.
|
|
|
|
|
*/
|
|
|
|
|
bool allow_24bit = !is_sub;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = start_op_idx; i < 2; i++) {
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[i]);
|
|
|
|
|
if (!op_instr)
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-11-18 13:07:57 +01:00
|
|
|
if (op_instr->opcode != aco_opcode::s_lshl_b32 &&
|
|
|
|
|
op_instr->opcode != aco_opcode::v_lshlrev_b32)
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
continue;
|
|
|
|
|
|
2020-11-18 13:07:57 +01:00
|
|
|
int shift_op_idx = op_instr->opcode == aco_opcode::s_lshl_b32 ? 1 : 0;
|
2021-09-09 08:38:41 +02:00
|
|
|
|
2020-11-18 13:07:57 +01:00
|
|
|
if (op_instr->operands[shift_op_idx].isConstant() &&
|
2021-09-09 08:38:41 +02:00
|
|
|
((allow_24bit && op_instr->operands[!shift_op_idx].is24bit()) ||
|
2020-11-18 13:07:57 +01:00
|
|
|
op_instr->operands[!shift_op_idx].is16bit())) {
|
2021-09-09 08:38:41 +02:00
|
|
|
uint32_t multiplier = 1 << (op_instr->operands[shift_op_idx].constantValue() % 32u);
|
|
|
|
|
if (is_sub)
|
|
|
|
|
multiplier = -multiplier;
|
|
|
|
|
if (is_sub ? (multiplier < 0xff800000) : (multiplier > 0xffffff))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Operand ops[3] = {
|
|
|
|
|
op_instr->operands[!shift_op_idx],
|
|
|
|
|
Operand::c32(multiplier),
|
|
|
|
|
instr->operands[!i],
|
|
|
|
|
};
|
|
|
|
|
if (!check_vop3_operands(ctx, 3, ops))
|
|
|
|
|
return false;
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
|
2021-09-09 08:38:41 +02:00
|
|
|
aco_opcode mad_op = is_sub ? aco_opcode::v_mad_i32_i24 : aco_opcode::v_mad_u32_u24;
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> new_instr{create_instruction(mad_op, Format::VOP3, 3, 1)};
|
2021-09-09 08:38:41 +02:00
|
|
|
for (unsigned op_idx = 0; op_idx < 3; ++op_idx)
|
|
|
|
|
new_instr->operands[op_idx] = ops[op_idx];
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
2023-05-09 20:24:52 +02:00
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
instr = std::move(new_instr);
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 15:07:09 +01:00
|
|
|
void
|
2023-03-07 14:38:34 +01:00
|
|
|
propagate_swizzles(VALU_instruction* instr, bool opsel_lo, bool opsel_hi)
|
2021-01-07 15:07:09 +01:00
|
|
|
{
|
|
|
|
|
/* propagate swizzles which apply to a result down to the instruction's operands:
|
|
|
|
|
* result = a.xy + b.xx -> result.yx = a.yx + b.xx */
|
|
|
|
|
uint8_t tmp_lo = instr->opsel_lo;
|
|
|
|
|
uint8_t tmp_hi = instr->opsel_hi;
|
2023-03-07 14:07:23 +01:00
|
|
|
uint8_t neg_lo = instr->neg_lo;
|
|
|
|
|
uint8_t neg_hi = instr->neg_hi;
|
2021-01-07 15:07:09 +01:00
|
|
|
if (opsel_lo == 1) {
|
|
|
|
|
instr->opsel_lo = tmp_hi;
|
2023-03-07 14:07:23 +01:00
|
|
|
instr->neg_lo = neg_hi;
|
2021-01-07 15:07:09 +01:00
|
|
|
}
|
|
|
|
|
if (opsel_hi == 0) {
|
|
|
|
|
instr->opsel_hi = tmp_lo;
|
2023-03-07 14:07:23 +01:00
|
|
|
instr->neg_hi = neg_lo;
|
2021-01-07 15:07:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
void
|
|
|
|
|
combine_vop3p(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
2020-09-03 12:02:55 +01:00
|
|
|
{
|
2023-02-21 20:08:42 +01:00
|
|
|
VALU_instruction* vop3p = &instr->valu();
|
2020-09-11 15:54:39 +01:00
|
|
|
|
|
|
|
|
/* apply clamp */
|
|
|
|
|
if (instr->opcode == aco_opcode::v_pk_mul_f16 && instr->operands[1].constantEquals(0x3C00) &&
|
2022-07-07 12:27:08 +02:00
|
|
|
vop3p->clamp && instr->operands[0].isTemp() && ctx.uses[instr->operands[0].tempId()] == 1 &&
|
2023-03-07 14:38:34 +01:00
|
|
|
!vop3p->opsel_lo[1] && !vop3p->opsel_hi[1]) {
|
2020-09-11 15:54:39 +01:00
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
Instruction* op_instr = ctx.info[instr->operands[0].tempId()].parent_instr;
|
2025-08-24 08:45:28 +02:00
|
|
|
const aco_alu_opcode_info& opcode_info = instr_info.alu_opcode_infos[(int)op_instr->opcode];
|
|
|
|
|
aco_type op_type = opcode_info.def_types[0];
|
|
|
|
|
if (op_instr->isVOP3P() && op_type.num_components == 2 &&
|
|
|
|
|
op_type.base_type == aco_base_type_float && op_type.bit_size == 16 &&
|
|
|
|
|
opcode_info.output_modifiers) {
|
2024-07-30 11:31:15 +02:00
|
|
|
op_instr->valu().clamp = true;
|
|
|
|
|
propagate_swizzles(&op_instr->valu(), vop3p->opsel_lo[0], vop3p->opsel_hi[0]);
|
|
|
|
|
instr->definitions[0].swapTemp(op_instr->definitions[0]);
|
|
|
|
|
ctx.info[op_instr->definitions[0].tempId()].parent_instr = op_instr;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2020-09-11 15:54:39 +01:00
|
|
|
ctx.uses[instr->definitions[0].tempId()]--;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 12:02:55 +01:00
|
|
|
|
2021-08-05 15:52:08 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_pk_add_f16 || instr->opcode == aco_opcode::v_pk_add_u16) {
|
|
|
|
|
bool fadd = instr->opcode == aco_opcode::v_pk_add_f16;
|
|
|
|
|
if (fadd && instr->definitions[0].isPrecise())
|
2020-09-03 12:02:55 +01:00
|
|
|
return;
|
2024-03-27 13:51:04 +01:00
|
|
|
if (!fadd && instr->valu().clamp)
|
|
|
|
|
return;
|
2020-09-03 12:02:55 +01:00
|
|
|
|
|
|
|
|
Instruction* mul_instr = nullptr;
|
|
|
|
|
unsigned add_op_idx = 0;
|
2023-03-09 14:51:50 +01:00
|
|
|
bitarray8 mul_neg_lo = 0, mul_neg_hi = 0, mul_opsel_lo = 0, mul_opsel_hi = 0;
|
2020-09-03 12:02:55 +01:00
|
|
|
uint32_t uses = UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
/* find the 'best' mul instruction to combine with the add */
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
2023-03-09 14:51:50 +01:00
|
|
|
Instruction* op_instr = follow_operand(ctx, instr->operands[i], true);
|
|
|
|
|
if (!op_instr)
|
2020-09-03 12:02:55 +01:00
|
|
|
continue;
|
2023-03-09 14:51:50 +01:00
|
|
|
|
2024-07-15 18:53:19 +02:00
|
|
|
if (op_instr->isVOP3P()) {
|
2023-03-09 14:51:50 +01:00
|
|
|
if (fadd) {
|
|
|
|
|
if (op_instr->opcode != aco_opcode::v_pk_mul_f16 ||
|
|
|
|
|
op_instr->definitions[0].isPrecise())
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if (op_instr->opcode != aco_opcode::v_pk_mul_lo_u16)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no clamp allowed between mul and add */
|
|
|
|
|
if (op_instr->valu().clamp)
|
2021-08-05 15:52:08 +02:00
|
|
|
continue;
|
2020-09-03 12:02:55 +01:00
|
|
|
|
2025-09-08 16:58:46 +02:00
|
|
|
Operand op[3] = {op_instr->operands[0], op_instr->operands[1], instr->operands[1 - i]};
|
|
|
|
|
if (ctx.uses[instr->operands[i].tempId()] >= uses || !check_vop3_operands(ctx, 3, op))
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-03-09 14:51:50 +01:00
|
|
|
mul_instr = op_instr;
|
|
|
|
|
add_op_idx = 1 - i;
|
|
|
|
|
uses = ctx.uses[instr->operands[i].tempId()];
|
|
|
|
|
mul_neg_lo = mul_instr->valu().neg_lo;
|
|
|
|
|
mul_neg_hi = mul_instr->valu().neg_hi;
|
|
|
|
|
mul_opsel_lo = mul_instr->valu().opsel_lo;
|
|
|
|
|
mul_opsel_hi = mul_instr->valu().opsel_hi;
|
|
|
|
|
} else if (instr->operands[i].bytes() == 2) {
|
|
|
|
|
if ((fadd && (op_instr->opcode != aco_opcode::v_mul_f16 ||
|
|
|
|
|
op_instr->definitions[0].isPrecise())) ||
|
|
|
|
|
(!fadd && op_instr->opcode != aco_opcode::v_mul_lo_u16 &&
|
|
|
|
|
op_instr->opcode != aco_opcode::v_mul_lo_u16_e64))
|
|
|
|
|
continue;
|
2020-09-03 12:02:55 +01:00
|
|
|
|
2023-03-09 14:51:50 +01:00
|
|
|
if (op_instr->valu().clamp || op_instr->valu().omod || op_instr->valu().abs)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (op_instr->isDPP() || (op_instr->isSDWA() && (op_instr->sdwa().sel[0].size() < 2 ||
|
|
|
|
|
op_instr->sdwa().sel[1].size() < 2)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Operand op[3] = {op_instr->operands[0], op_instr->operands[1], instr->operands[1 - i]};
|
|
|
|
|
if (ctx.uses[instr->operands[i].tempId()] >= uses || !check_vop3_operands(ctx, 3, op))
|
|
|
|
|
continue;
|
2020-09-03 12:02:55 +01:00
|
|
|
|
2023-03-09 14:51:50 +01:00
|
|
|
mul_instr = op_instr;
|
|
|
|
|
add_op_idx = 1 - i;
|
|
|
|
|
uses = ctx.uses[instr->operands[i].tempId()];
|
|
|
|
|
mul_neg_lo = mul_instr->valu().neg;
|
|
|
|
|
mul_neg_hi = mul_instr->valu().neg;
|
|
|
|
|
if (mul_instr->isSDWA()) {
|
|
|
|
|
for (unsigned j = 0; j < 2; j++)
|
|
|
|
|
mul_opsel_lo[j] = mul_instr->sdwa().sel[j].offset();
|
|
|
|
|
} else {
|
|
|
|
|
mul_opsel_lo = mul_instr->valu().opsel;
|
|
|
|
|
}
|
|
|
|
|
mul_opsel_hi = mul_opsel_lo;
|
|
|
|
|
}
|
2020-09-03 12:02:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mul_instr)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-09 14:51:50 +01:00
|
|
|
/* turn mul + packed add into v_pk_fma_f16 */
|
2021-08-05 15:52:08 +02:00
|
|
|
aco_opcode mad = fadd ? aco_opcode::v_pk_fma_f16 : aco_opcode::v_pk_mad_u16;
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> fma{create_instruction(mad, Format::VOP3P, 3, 1)};
|
2023-03-09 14:51:50 +01:00
|
|
|
fma->operands[0] = copy_operand(ctx, mul_instr->operands[0]);
|
|
|
|
|
fma->operands[1] = copy_operand(ctx, mul_instr->operands[1]);
|
2023-03-09 14:17:53 +01:00
|
|
|
fma->operands[2] = instr->operands[add_op_idx];
|
2024-03-25 12:05:50 +01:00
|
|
|
fma->valu().clamp = vop3p->clamp;
|
|
|
|
|
fma->valu().neg_lo = mul_neg_lo;
|
|
|
|
|
fma->valu().neg_hi = mul_neg_hi;
|
|
|
|
|
fma->valu().opsel_lo = mul_opsel_lo;
|
|
|
|
|
fma->valu().opsel_hi = mul_opsel_hi;
|
|
|
|
|
propagate_swizzles(&fma->valu(), vop3p->opsel_lo[1 - add_op_idx],
|
2023-03-09 14:51:50 +01:00
|
|
|
vop3p->opsel_hi[1 - add_op_idx]);
|
2024-03-25 12:05:50 +01:00
|
|
|
fma->valu().opsel_lo[2] = vop3p->opsel_lo[add_op_idx];
|
|
|
|
|
fma->valu().opsel_hi[2] = vop3p->opsel_hi[add_op_idx];
|
|
|
|
|
fma->valu().neg_lo[2] = vop3p->neg_lo[add_op_idx];
|
|
|
|
|
fma->valu().neg_hi[2] = vop3p->neg_hi[add_op_idx];
|
|
|
|
|
fma->valu().neg_lo[1] = fma->valu().neg_lo[1] ^ vop3p->neg_lo[1 - add_op_idx];
|
|
|
|
|
fma->valu().neg_hi[1] = fma->valu().neg_hi[1] ^ vop3p->neg_hi[1 - add_op_idx];
|
2020-09-03 12:02:55 +01:00
|
|
|
fma->definitions[0] = instr->definitions[0];
|
2023-05-09 20:24:52 +02:00
|
|
|
fma->pass_flags = instr->pass_flags;
|
2021-09-16 20:50:29 +02:00
|
|
|
instr = std::move(fma);
|
2024-07-30 11:31:15 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2025-06-04 17:06:41 +02:00
|
|
|
decrease_and_dce(ctx, mul_instr->definitions[0].getTemp());
|
2020-09-03 12:02:55 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
bool
|
|
|
|
|
can_use_mad_mix(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.program->gfx_level < GFX9)
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
aco: don't use v_mad_mix on GFX9 if 16-bit denormals must be preserved
This probably effectively disables the v_mad_mix optimization on GFX9.
fossil-db (Vega):
Totals from 11545 (7.15% of 161366) affected shaders:
MaxWaves: 43025 -> 42780 (-0.57%); split: +0.06%, -0.63%
Instrs: 18571635 -> 18734201 (+0.88%); split: -0.00%, +0.88%
CodeSize: 96483568 -> 96611012 (+0.13%); split: -0.11%, +0.24%
SGPRs: 1079056 -> 1077616 (-0.13%); split: -0.14%, +0.01%
VGPRs: 819248 -> 821868 (+0.32%); split: -0.04%, +0.36%
SpillSGPRs: 13313 -> 12464 (-6.38%)
Latency: 293804093 -> 295046122 (+0.42%); split: -0.09%, +0.51%
InvThroughput: 110002239 -> 110994978 (+0.90%); split: -0.03%, +0.93%
VClause: 342458 -> 342596 (+0.04%); split: -0.12%, +0.16%
SClause: 648566 -> 648046 (-0.08%); split: -0.12%, +0.04%
Copies: 1728225 -> 1726679 (-0.09%); split: -0.66%, +0.57%
Branches: 552973 -> 552963 (-0.00%); split: -0.02%, +0.02%
PreSGPRs: 862360 -> 856820 (-0.64%); split: -0.69%, +0.05%
PreVGPRs: 773689 -> 776818 (+0.40%); split: -0.02%, +0.42%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6178
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15718>
2022-04-01 19:51:55 +01:00
|
|
|
/* v_mad_mix* on GFX9 always flushes denormals for 16-bit inputs/outputs */
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.program->gfx_level == GFX9 && ctx.fp_mode.denorm16_64)
|
aco: don't use v_mad_mix on GFX9 if 16-bit denormals must be preserved
This probably effectively disables the v_mad_mix optimization on GFX9.
fossil-db (Vega):
Totals from 11545 (7.15% of 161366) affected shaders:
MaxWaves: 43025 -> 42780 (-0.57%); split: +0.06%, -0.63%
Instrs: 18571635 -> 18734201 (+0.88%); split: -0.00%, +0.88%
CodeSize: 96483568 -> 96611012 (+0.13%); split: -0.11%, +0.24%
SGPRs: 1079056 -> 1077616 (-0.13%); split: -0.14%, +0.01%
VGPRs: 819248 -> 821868 (+0.32%); split: -0.04%, +0.36%
SpillSGPRs: 13313 -> 12464 (-6.38%)
Latency: 293804093 -> 295046122 (+0.42%); split: -0.09%, +0.51%
InvThroughput: 110002239 -> 110994978 (+0.90%); split: -0.03%, +0.93%
VClause: 342458 -> 342596 (+0.04%); split: -0.12%, +0.16%
SClause: 648566 -> 648046 (-0.08%); split: -0.12%, +0.04%
Copies: 1728225 -> 1726679 (-0.09%); split: -0.66%, +0.57%
Branches: 552973 -> 552963 (-0.00%); split: -0.02%, +0.02%
PreSGPRs: 862360 -> 856820 (-0.64%); split: -0.69%, +0.05%
PreVGPRs: 773689 -> 776818 (+0.40%); split: -0.02%, +0.42%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6178
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15718>
2022-04-01 19:51:55 +01:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-14 13:15:39 +02:00
|
|
|
if (instr->valu().omod)
|
|
|
|
|
return false;
|
|
|
|
|
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::v_add_f32:
|
|
|
|
|
case aco_opcode::v_sub_f32:
|
|
|
|
|
case aco_opcode::v_subrev_f32:
|
2023-09-14 13:15:39 +02:00
|
|
|
case aco_opcode::v_mul_f32: return !instr->isSDWA() && !instr->isDPP();
|
|
|
|
|
case aco_opcode::v_fma_f32:
|
|
|
|
|
return ctx.program->dev.fused_mad_mix || !instr->definitions[0].isPrecise();
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
case aco_opcode::v_fma_mix_f32:
|
|
|
|
|
case aco_opcode::v_fma_mixlo_f16: return true;
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
to_mad_mix(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2024-07-30 11:31:15 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label &= label_f2f16 | label_clamp;
|
2023-09-14 13:15:39 +02:00
|
|
|
|
|
|
|
|
if (instr->opcode == aco_opcode::v_fma_f32) {
|
|
|
|
|
instr->format = (Format)((uint32_t)withoutVOP3(instr->format) | (uint32_t)(Format::VOP3P));
|
|
|
|
|
instr->opcode = aco_opcode::v_fma_mix_f32;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_add = instr->opcode != aco_opcode::v_mul_f32;
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> vop3p{create_instruction(aco_opcode::v_fma_mix_f32, Format::VOP3P, 3, 1)};
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
vop3p->operands[is_add + i] = instr->operands[i];
|
2024-03-25 12:05:50 +01:00
|
|
|
vop3p->valu().neg_lo[is_add + i] = instr->valu().neg[i];
|
|
|
|
|
vop3p->valu().neg_hi[is_add + i] = instr->valu().abs[i];
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
if (instr->opcode == aco_opcode::v_mul_f32) {
|
|
|
|
|
vop3p->operands[2] = Operand::zero();
|
2024-03-25 12:05:50 +01:00
|
|
|
vop3p->valu().neg_lo[2] = true;
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
} else if (is_add) {
|
|
|
|
|
vop3p->operands[0] = Operand::c32(0x3f800000);
|
|
|
|
|
if (instr->opcode == aco_opcode::v_sub_f32)
|
2024-03-25 12:05:50 +01:00
|
|
|
vop3p->valu().neg_lo[2] ^= true;
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
else if (instr->opcode == aco_opcode::v_subrev_f32)
|
2024-03-25 12:05:50 +01:00
|
|
|
vop3p->valu().neg_lo[1] ^= true;
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
vop3p->definitions[0] = instr->definitions[0];
|
2024-03-25 12:05:50 +01:00
|
|
|
vop3p->valu().clamp = instr->valu().clamp;
|
2023-05-09 20:24:52 +02:00
|
|
|
vop3p->pass_flags = instr->pass_flags;
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
instr = std::move(vop3p);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-17 16:52:10 +00:00
|
|
|
bool
|
|
|
|
|
combine_output_conversion(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
ssa_info& def_info = ctx.info[instr->definitions[0].tempId()];
|
|
|
|
|
if (!def_info.is_f2f16())
|
|
|
|
|
return false;
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* conv = def_info.mod_instr;
|
2022-01-17 16:52:10 +00:00
|
|
|
|
2023-09-14 13:25:07 +02:00
|
|
|
if (!ctx.uses[conv->definitions[0].tempId()] || ctx.uses[instr->definitions[0].tempId()] != 1)
|
2022-01-17 16:52:10 +00:00
|
|
|
return false;
|
|
|
|
|
|
2023-09-14 13:25:07 +02:00
|
|
|
if (conv->usesModifiers())
|
2022-01-17 16:52:10 +00:00
|
|
|
return false;
|
|
|
|
|
|
2024-08-01 15:02:45 +01:00
|
|
|
if (interp_can_become_fma(ctx, instr))
|
2023-09-14 13:25:07 +02:00
|
|
|
interp_p2_f32_inreg_to_fma_dpp(instr);
|
|
|
|
|
|
|
|
|
|
if (!can_use_mad_mix(ctx, instr))
|
2022-01-17 16:52:10 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!instr->isVOP3P())
|
|
|
|
|
to_mad_mix(ctx, instr);
|
|
|
|
|
|
|
|
|
|
instr->opcode = aco_opcode::v_fma_mixlo_f16;
|
|
|
|
|
instr->definitions[0].swapTemp(conv->definitions[0]);
|
|
|
|
|
if (conv->definitions[0].isPrecise())
|
|
|
|
|
instr->definitions[0].setPrecise(true);
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].label &= label_clamp;
|
|
|
|
|
ctx.uses[conv->definitions[0].tempId()]--;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[conv->definitions[0].tempId()].parent_instr = conv;
|
2022-01-17 16:52:10 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
// TODO: we could possibly move the whole label_instruction pass to combine_instruction:
|
|
|
|
|
// this would mean that we'd have to fix the instruction uses while value propagation
|
|
|
|
|
|
2022-04-11 17:51:42 +01:00
|
|
|
/* also returns true for inf */
|
|
|
|
|
bool
|
|
|
|
|
is_pow_of_two(opt_ctx& ctx, Operand op)
|
|
|
|
|
{
|
|
|
|
|
if (op.isTemp() && ctx.info[op.tempId()].is_constant_or_literal(op.bytes() * 8))
|
|
|
|
|
return is_pow_of_two(ctx, get_constant_op(ctx, ctx.info[op.tempId()], op.bytes() * 8));
|
|
|
|
|
else if (!op.isConstant())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
uint64_t val = op.constantValue64();
|
|
|
|
|
|
|
|
|
|
if (op.bytes() == 4) {
|
|
|
|
|
uint32_t exponent = (val & 0x7f800000) >> 23;
|
|
|
|
|
uint32_t fraction = val & 0x007fffff;
|
|
|
|
|
return (exponent >= 127) && (fraction == 0);
|
|
|
|
|
} else if (op.bytes() == 2) {
|
|
|
|
|
uint32_t exponent = (val & 0x7c00) >> 10;
|
|
|
|
|
uint32_t fraction = val & 0x03ff;
|
|
|
|
|
return (exponent >= 15) && (fraction == 0);
|
|
|
|
|
} else {
|
|
|
|
|
assert(op.bytes() == 8);
|
|
|
|
|
uint64_t exponent = (val & UINT64_C(0x7ff0000000000000)) >> 52;
|
|
|
|
|
uint64_t fraction = val & UINT64_C(0x000fffffffffffff);
|
|
|
|
|
return (exponent >= 1023) && (fraction == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 15:36:05 +02:00
|
|
|
bool
|
|
|
|
|
is_mul(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::v_mul_f64_e64:
|
|
|
|
|
case aco_opcode::v_mul_f64:
|
|
|
|
|
case aco_opcode::v_mul_f32:
|
|
|
|
|
case aco_opcode::v_mul_legacy_f32:
|
|
|
|
|
case aco_opcode::v_mul_f16: return true;
|
|
|
|
|
case aco_opcode::v_fma_mix_f32:
|
|
|
|
|
return instr->operands[2].constantEquals(0) && instr->valu().neg[2];
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
void
|
|
|
|
|
combine_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2019-11-19 13:38:34 +01:00
|
|
|
if (instr->definitions.empty() || is_dead(ctx.uses, instr.get()))
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-10-25 12:00:45 +02:00
|
|
|
for (const Definition& def : instr->definitions) {
|
|
|
|
|
ssa_info& info = ctx.info[def.tempId()];
|
|
|
|
|
if (info.is_extract() && ctx.uses[def.tempId()] > 4)
|
|
|
|
|
info.label &= ~label_extract;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 15:25:13 +01:00
|
|
|
if (instr->isVALU() || instr->isSALU()) {
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
/* Apply SDWA. Do this after label_instruction() so it can remove
|
|
|
|
|
* label_extract if not all instructions can take SDWA. */
|
2024-10-25 12:00:45 +02:00
|
|
|
alu_propagate_temp_const(ctx, instr, true);
|
2024-06-06 15:25:13 +01:00
|
|
|
}
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
|
2024-06-06 15:25:13 +01:00
|
|
|
if (instr->isVALU()) {
|
2022-11-04 19:30:12 +08:00
|
|
|
while (apply_omod_clamp(ctx, instr) || combine_output_conversion(ctx, instr))
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
;
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
apply_insert(ctx, instr);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
if (instr->isVOP3P() && instr->opcode != aco_opcode::v_fma_mix_f32 &&
|
|
|
|
|
instr->opcode != aco_opcode::v_fma_mixlo_f16)
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
return combine_vop3p(ctx, instr);
|
2020-09-03 12:02:55 +01:00
|
|
|
|
2021-07-19 14:26:42 +01:00
|
|
|
if (instr->isSDWA() || instr->isDPP())
|
2019-12-05 14:12:39 +00:00
|
|
|
return;
|
|
|
|
|
|
2024-11-23 16:10:19 +01:00
|
|
|
if (instr->opcode == aco_opcode::p_extract) {
|
|
|
|
|
apply_load_extract(ctx, instr);
|
2021-10-05 13:09:02 +01:00
|
|
|
}
|
2021-08-27 15:45:59 +02:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* TODO: There are still some peephole optimizations that could be done:
|
|
|
|
|
* - abs(a - b) -> s_absdiff_i32
|
|
|
|
|
* - various patterns for s_bitcmp{0,1}_b32 and s_bitset{0,1}_b32
|
|
|
|
|
* - patterns for v_alignbit_b32 and v_alignbyte_b32
|
|
|
|
|
* These aren't probably too interesting though.
|
|
|
|
|
* There are also patterns for v_cmp_class_f{16,32,64}. This is difficult but
|
|
|
|
|
* probably more useful than the previously mentioned optimizations.
|
|
|
|
|
* The various comparison optimizations also currently only work with 32-bit
|
|
|
|
|
* floats. */
|
|
|
|
|
|
2022-01-28 13:47:16 +00:00
|
|
|
/* neg(mul(a, b)) -> mul(neg(a), b), abs(mul(a, b)) -> mul(abs(a), abs(b)) */
|
|
|
|
|
if ((ctx.info[instr->definitions[0].tempId()].label & (label_neg | label_abs)) &&
|
2025-09-30 19:07:19 +02:00
|
|
|
ctx.uses[ctx.info[instr->definitions[0].tempId()].temp.id()] == 1) {
|
2019-09-17 13:22:17 +02:00
|
|
|
Temp val = ctx.info[instr->definitions[0].tempId()].temp;
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* mul_instr = ctx.info[val.id()].parent_instr;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-07-23 15:36:05 +02:00
|
|
|
if (!is_mul(mul_instr))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
if (mul_instr->operands[0].isLiteral())
|
|
|
|
|
return;
|
2023-03-24 13:30:01 +01:00
|
|
|
if (mul_instr->valu().clamp)
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
2023-03-24 13:30:01 +01:00
|
|
|
if (mul_instr->isSDWA() || mul_instr->isDPP())
|
2019-12-05 14:12:39 +00:00
|
|
|
return;
|
2021-09-21 17:03:05 +01:00
|
|
|
if (mul_instr->opcode == aco_opcode::v_mul_legacy_f32 &&
|
2024-09-13 20:06:46 +02:00
|
|
|
mul_instr->definitions[0].isSZPreserve())
|
2021-09-21 17:03:05 +01:00
|
|
|
return;
|
2022-01-31 18:28:59 +00:00
|
|
|
if (mul_instr->definitions[0].bytes() != instr->definitions[0].bytes())
|
|
|
|
|
return;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2022-01-28 13:47:16 +00:00
|
|
|
/* convert to mul(neg(a), b), mul(abs(a), abs(b)) or mul(neg(abs(a)), abs(b)) */
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.uses[mul_instr->definitions[0].tempId()]--;
|
|
|
|
|
Definition def = instr->definitions[0];
|
2022-01-28 13:47:16 +00:00
|
|
|
bool is_neg = ctx.info[instr->definitions[0].tempId()].is_neg();
|
2019-09-17 13:22:17 +02:00
|
|
|
bool is_abs = ctx.info[instr->definitions[0].tempId()].is_abs();
|
2023-05-09 20:24:52 +02:00
|
|
|
uint32_t pass_flags = instr->pass_flags;
|
2023-03-24 13:30:01 +01:00
|
|
|
Format format = mul_instr->format == Format::VOP2 ? asVOP3(Format::VOP2) : mul_instr->format;
|
2024-03-25 15:55:27 +01:00
|
|
|
instr.reset(create_instruction(mul_instr->opcode, format, mul_instr->operands.size(), 1));
|
2023-03-24 13:30:01 +01:00
|
|
|
std::copy(mul_instr->operands.cbegin(), mul_instr->operands.cend(), instr->operands.begin());
|
2023-05-09 20:24:52 +02:00
|
|
|
instr->pass_flags = pass_flags;
|
2019-09-17 13:22:17 +02:00
|
|
|
instr->definitions[0] = def;
|
2023-02-21 20:08:42 +01:00
|
|
|
VALU_instruction& new_mul = instr->valu();
|
2023-03-24 13:30:01 +01:00
|
|
|
VALU_instruction& mul = mul_instr->valu();
|
|
|
|
|
new_mul.neg = mul.neg;
|
|
|
|
|
new_mul.abs = mul.abs;
|
|
|
|
|
new_mul.omod = mul.omod;
|
|
|
|
|
new_mul.opsel = mul.opsel;
|
|
|
|
|
new_mul.opsel_lo = mul.opsel_lo;
|
|
|
|
|
new_mul.opsel_hi = mul.opsel_hi;
|
2022-01-28 13:48:34 +00:00
|
|
|
if (is_abs) {
|
|
|
|
|
new_mul.neg[0] = new_mul.neg[1] = false;
|
|
|
|
|
new_mul.abs[0] = new_mul.abs[1] = true;
|
|
|
|
|
}
|
2022-01-28 13:47:16 +00:00
|
|
|
new_mul.neg[0] ^= is_neg;
|
2021-01-21 16:13:34 +00:00
|
|
|
new_mul.clamp = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2024-07-30 11:31:15 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-05-15 14:03:15 +01:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* combine mul+add -> mad */
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
bool is_add_mix =
|
|
|
|
|
(instr->opcode == aco_opcode::v_fma_mix_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_fma_mixlo_f16) &&
|
2023-02-21 20:08:42 +01:00
|
|
|
!instr->valu().neg_lo[0] &&
|
2023-03-07 14:38:34 +01:00
|
|
|
((instr->operands[0].constantEquals(0x3f800000) && !instr->valu().opsel_hi[0]) ||
|
|
|
|
|
(instr->operands[0].constantEquals(0x3C00) && instr->valu().opsel_hi[0] &&
|
|
|
|
|
!instr->valu().opsel_lo[0]));
|
2020-05-15 14:03:15 +01:00
|
|
|
bool mad32 = instr->opcode == aco_opcode::v_add_f32 || instr->opcode == aco_opcode::v_sub_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_subrev_f32;
|
2020-05-14 21:09:36 +01:00
|
|
|
bool mad16 = instr->opcode == aco_opcode::v_add_f16 || instr->opcode == aco_opcode::v_sub_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_subrev_f16;
|
2024-03-11 14:16:53 +00:00
|
|
|
bool mad64 =
|
|
|
|
|
instr->opcode == aco_opcode::v_add_f64_e64 || instr->opcode == aco_opcode::v_add_f64;
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
if (is_add_mix || mad16 || mad32 || mad64) {
|
2019-09-17 13:22:17 +02:00
|
|
|
Instruction* mul_instr = nullptr;
|
2020-09-03 12:02:55 +01:00
|
|
|
unsigned add_op_idx = 0;
|
2020-09-02 15:19:21 +01:00
|
|
|
uint32_t uses = UINT32_MAX;
|
2022-01-17 17:33:25 +00:00
|
|
|
bool emit_fma = false;
|
2019-09-17 13:22:17 +02:00
|
|
|
/* find the 'best' mul instruction to combine with the add */
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
for (unsigned i = is_add_mix ? 1 : 0; i < instr->operands.size(); i++) {
|
2025-05-09 11:34:49 +02:00
|
|
|
if (!instr->operands[i].isTemp())
|
2020-09-02 15:19:21 +01:00
|
|
|
continue;
|
|
|
|
|
ssa_info& info = ctx.info[instr->operands[i].tempId()];
|
2024-07-23 17:49:32 +02:00
|
|
|
if (!is_mul(info.parent_instr))
|
2024-07-23 15:36:05 +02:00
|
|
|
continue;
|
2020-09-02 15:19:21 +01:00
|
|
|
|
|
|
|
|
/* no clamp/omod allowed between mul and add */
|
2024-07-23 17:49:32 +02:00
|
|
|
if (info.parent_instr->isVOP3() &&
|
|
|
|
|
(info.parent_instr->valu().clamp || info.parent_instr->valu().omod))
|
2020-09-02 15:19:21 +01:00
|
|
|
continue;
|
2024-07-23 17:49:32 +02:00
|
|
|
if (info.parent_instr->isVOP3P() && info.parent_instr->valu().clamp)
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
continue;
|
|
|
|
|
/* v_fma_mix_f32/etc can't do omod */
|
2024-07-23 17:49:32 +02:00
|
|
|
if (info.parent_instr->isVOP3P() && instr->isVOP3() && instr->valu().omod)
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
continue;
|
|
|
|
|
/* don't promote fp16 to fp32 or remove fp32->fp16->fp32 conversions */
|
2024-07-23 17:49:32 +02:00
|
|
|
if (is_add_mix && info.parent_instr->definitions[0].bytes() == 2)
|
aco: use v_fma_mix to combine mul/add/fma input conversions
fossil-db (Sienna Cichlid):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 829392 -> 825200 (-0.51%); split: -0.52%, +0.02%
SpillSGPRs: 7845 -> 8399 (+7.06%)
CodeSize: 101822704 -> 101677172 (-0.14%); split: -0.25%, +0.11%
MaxWaves: 172216 -> 173182 (+0.56%); split: +0.59%, -0.03%
Instrs: 19061343 -> 18883450 (-0.93%); split: -0.93%, +0.00%
Latency: 256011590 -> 255177378 (-0.33%); split: -0.39%, +0.06%
InvThroughput: 46104438 -> 45604059 (-1.09%); split: -1.12%, +0.04%
VClause: 352211 -> 351948 (-0.07%); split: -0.21%, +0.13%
SClause: 676506 -> 676961 (+0.07%); split: -0.04%, +0.11%
Copies: 1246571 -> 1237745 (-0.71%); split: -0.97%, +0.26%
Branches: 626229 -> 626241 (+0.00%); split: -0.02%, +0.03%
PreSGPRs: 882176 -> 888853 (+0.76%); split: -0.00%, +0.76%
PreVGPRs: 796705 -> 792304 (-0.55%); split: -0.56%, +0.00%
fossil-db (Navi):
Totals from 11558 (8.57% of 134913) affected shaders:
VGPRs: 803900 -> 798660 (-0.65%); split: -0.73%, +0.08%
SpillSGPRs: 7894 -> 8492 (+7.58%); split: -0.10%, +7.68%
CodeSize: 96892596 -> 97134716 (+0.25%); split: -0.05%, +0.29%
MaxWaves: 181454 -> 183014 (+0.86%); split: +0.94%, -0.08%
Instrs: 18186813 -> 18093994 (-0.51%); split: -0.56%, +0.05%
Latency: 253385909 -> 253325528 (-0.02%); split: -0.15%, +0.12%
InvThroughput: 43315355 -> 42805541 (-1.18%); split: -1.33%, +0.15%
VClause: 338755 -> 338535 (-0.06%); split: -0.16%, +0.10%
SClause: 656561 -> 656829 (+0.04%); split: -0.07%, +0.11%
Copies: 1162235 -> 1153558 (-0.75%); split: -1.07%, +0.32%
Branches: 588536 -> 588542 (+0.00%); split: -0.03%, +0.03%
PreSGPRs: 854849 -> 861640 (+0.79%); split: -0.00%, +0.80%
PreVGPRs: 783401 -> 779031 (-0.56%); split: -0.56%, +0.00%
fossil-db (Vega):
Totals from 11516 (8.53% of 135048) affected shaders:
SGPRs: 1072128 -> 1076288 (+0.39%); split: -0.01%, +0.40%
VGPRs: 821312 -> 818124 (-0.39%); split: -0.43%, +0.04%
SpillSGPRs: 11952 -> 12677 (+6.07%)
CodeSize: 96378496 -> 96707596 (+0.34%); split: -0.04%, +0.38%
MaxWaves: 42614 -> 42883 (+0.63%); split: +0.68%, -0.04%
Instrs: 18672844 -> 18600274 (-0.39%); split: -0.44%, +0.05%
Latency: 296658786 -> 296338296 (-0.11%); split: -0.21%, +0.10%
InvThroughput: 111665547 -> 111283559 (-0.34%); split: -0.40%, +0.06%
VClause: 343001 -> 342826 (-0.05%); split: -0.14%, +0.09%
SClause: 646684 -> 646657 (-0.00%); split: -0.05%, +0.04%
Copies: 1715316 -> 1712895 (-0.14%); split: -0.53%, +0.39%
PreSGPRs: 850737 -> 856543 (+0.68%); split: -0.04%, +0.72%
PreVGPRs: 775293 -> 772215 (-0.40%); split: -0.41%, +0.02%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 13:58:34 +00:00
|
|
|
continue;
|
2020-09-02 15:19:21 +01:00
|
|
|
|
2025-05-16 12:20:49 +02:00
|
|
|
if (get_operand_type(instr, i).bytes() != info.parent_instr->definitions[0].bytes())
|
2022-01-31 18:22:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
bool legacy = info.parent_instr->opcode == aco_opcode::v_mul_legacy_f32;
|
|
|
|
|
bool mad_mix = is_add_mix || info.parent_instr->isVOP3P();
|
2022-01-17 17:33:25 +00:00
|
|
|
|
2022-04-11 17:51:42 +01:00
|
|
|
/* Multiplication by power-of-two should never need rounding. 1/power-of-two also works,
|
|
|
|
|
* but using fma removes denormal flushing (0xfffffe * 0.5 + 0x810001a2).
|
|
|
|
|
*/
|
2024-07-23 17:49:32 +02:00
|
|
|
bool is_fma_precise = is_pow_of_two(ctx, info.parent_instr->operands[0]) ||
|
|
|
|
|
is_pow_of_two(ctx, info.parent_instr->operands[1]);
|
2022-04-11 17:51:42 +01:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
bool has_fma = mad16 || mad64 || (legacy && ctx.program->gfx_level >= GFX10_3) ||
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
(mad32 && !legacy && !mad_mix && ctx.program->dev.has_fast_fma32) ||
|
|
|
|
|
(mad_mix && ctx.program->dev.fused_mad_mix);
|
|
|
|
|
bool has_mad = mad_mix ? !ctx.program->dev.fused_mad_mix
|
2025-06-26 11:49:55 +08:00
|
|
|
: ((mad32 && ctx.program->gfx_level < GFX10_3 &&
|
|
|
|
|
ctx.program->family != CHIP_GFX940) ||
|
2022-05-12 02:50:17 -04:00
|
|
|
(mad16 && ctx.program->gfx_level <= GFX9));
|
2024-07-23 17:49:32 +02:00
|
|
|
bool can_use_fma = has_fma && (!(info.parent_instr->definitions[0].isPrecise() ||
|
|
|
|
|
instr->definitions[0].isPrecise()) ||
|
|
|
|
|
is_fma_precise);
|
2022-01-17 17:33:25 +00:00
|
|
|
bool can_use_mad =
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
has_mad && (mad_mix || mad32 ? ctx.fp_mode.denorm32 : ctx.fp_mode.denorm16_64) == 0;
|
|
|
|
|
if (mad_mix && legacy)
|
|
|
|
|
continue;
|
2022-01-17 17:33:25 +00:00
|
|
|
if (!can_use_fma && !can_use_mad)
|
2021-09-21 17:03:05 +01:00
|
|
|
continue;
|
|
|
|
|
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
unsigned candidate_add_op_idx = is_add_mix ? (3 - i) : (1 - i);
|
2024-07-23 17:49:32 +02:00
|
|
|
Operand op[3] = {info.parent_instr->operands[0], info.parent_instr->operands[1],
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
instr->operands[candidate_add_op_idx]};
|
2024-07-23 17:49:32 +02:00
|
|
|
if (info.parent_instr->isSDWA() || info.parent_instr->isDPP() ||
|
|
|
|
|
!check_vop3_operands(ctx, 3, op) || ctx.uses[instr->operands[i].tempId()] > uses)
|
2020-09-02 15:19:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
aco: use more predictable tiebreaker when forming MADs
fossil-db (GFX10.3):
Totals from 84981 (58.10% of 146267) affected shaders:
VGPRs: 3829896 -> 3820480 (-0.25%); split: -0.33%, +0.08%
CodeSize: 270860472 -> 270850132 (-0.00%); split: -0.08%, +0.08%
MaxWaves: 2035822 -> 2042516 (+0.33%); split: +0.39%, -0.06%
Instrs: 51285526 -> 51308869 (+0.05%); split: -0.03%, +0.08%
Latency: 931503706 -> 932556231 (+0.11%); split: -0.19%, +0.30%
InvThroughput: 217084232 -> 217070849 (-0.01%); split: -0.12%, +0.11%
fossil-db (GFX10):
Totals from 85520 (58.47% of 146267) affected shaders:
VGPRs: 3729132 -> 3725344 (-0.10%); split: -0.21%, +0.10%
CodeSize: 272796500 -> 272783084 (-0.00%); split: -0.09%, +0.08%
MaxWaves: 2246410 -> 2249012 (+0.12%); split: +0.17%, -0.05%
Instrs: 51643962 -> 51664865 (+0.04%); split: -0.04%, +0.08%
Latency: 932331949 -> 933274979 (+0.10%); split: -0.19%, +0.29%
InvThroughput: 214187040 -> 214130994 (-0.03%); split: -0.13%, +0.11%
fossil-db (GFX9):
Totals from 84619 (57.80% of 146401) affected shaders:
SGPRs: 5366240 -> 5366944 (+0.01%); split: -0.09%, +0.10%
VGPRs: 3765608 -> 3764972 (-0.02%); split: -0.23%, +0.22%
CodeSize: 263634732 -> 263616320 (-0.01%); split: -0.08%, +0.08%
MaxWaves: 546617 -> 547091 (+0.09%); split: +0.18%, -0.09%
Instrs: 51426195 -> 51458334 (+0.06%); split: -0.03%, +0.10%
Latency: 1164445660 -> 1161923480 (-0.22%); split: -0.46%, +0.24%
InvThroughput: 542964697 -> 542329595 (-0.12%); split: -0.26%, +0.14%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9805>
2021-03-18 11:33:41 +00:00
|
|
|
if (ctx.uses[instr->operands[i].tempId()] == uses) {
|
|
|
|
|
unsigned cur_idx = mul_instr->definitions[0].tempId();
|
2024-07-23 17:49:32 +02:00
|
|
|
unsigned new_idx = info.parent_instr->definitions[0].tempId();
|
aco: use more predictable tiebreaker when forming MADs
fossil-db (GFX10.3):
Totals from 84981 (58.10% of 146267) affected shaders:
VGPRs: 3829896 -> 3820480 (-0.25%); split: -0.33%, +0.08%
CodeSize: 270860472 -> 270850132 (-0.00%); split: -0.08%, +0.08%
MaxWaves: 2035822 -> 2042516 (+0.33%); split: +0.39%, -0.06%
Instrs: 51285526 -> 51308869 (+0.05%); split: -0.03%, +0.08%
Latency: 931503706 -> 932556231 (+0.11%); split: -0.19%, +0.30%
InvThroughput: 217084232 -> 217070849 (-0.01%); split: -0.12%, +0.11%
fossil-db (GFX10):
Totals from 85520 (58.47% of 146267) affected shaders:
VGPRs: 3729132 -> 3725344 (-0.10%); split: -0.21%, +0.10%
CodeSize: 272796500 -> 272783084 (-0.00%); split: -0.09%, +0.08%
MaxWaves: 2246410 -> 2249012 (+0.12%); split: +0.17%, -0.05%
Instrs: 51643962 -> 51664865 (+0.04%); split: -0.04%, +0.08%
Latency: 932331949 -> 933274979 (+0.10%); split: -0.19%, +0.29%
InvThroughput: 214187040 -> 214130994 (-0.03%); split: -0.13%, +0.11%
fossil-db (GFX9):
Totals from 84619 (57.80% of 146401) affected shaders:
SGPRs: 5366240 -> 5366944 (+0.01%); split: -0.09%, +0.10%
VGPRs: 3765608 -> 3764972 (-0.02%); split: -0.23%, +0.22%
CodeSize: 263634732 -> 263616320 (-0.01%); split: -0.08%, +0.08%
MaxWaves: 546617 -> 547091 (+0.09%); split: +0.18%, -0.09%
Instrs: 51426195 -> 51458334 (+0.06%); split: -0.03%, +0.10%
Latency: 1164445660 -> 1161923480 (-0.22%); split: -0.46%, +0.24%
InvThroughput: 542964697 -> 542329595 (-0.12%); split: -0.26%, +0.14%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9805>
2021-03-18 11:33:41 +00:00
|
|
|
if (cur_idx > new_idx)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
mul_instr = info.parent_instr;
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
add_op_idx = candidate_add_op_idx;
|
2020-09-02 15:19:21 +01:00
|
|
|
uses = ctx.uses[instr->operands[i].tempId()];
|
2022-01-17 17:33:25 +00:00
|
|
|
emit_fma = !can_use_mad;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2020-09-02 15:19:21 +01:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
if (mul_instr) {
|
2020-09-02 15:19:21 +01:00
|
|
|
/* turn mul+add into v_mad/v_fma */
|
|
|
|
|
Operand op[3] = {mul_instr->operands[0], mul_instr->operands[1],
|
|
|
|
|
instr->operands[add_op_idx]};
|
|
|
|
|
ctx.uses[mul_instr->definitions[0].tempId()]--;
|
|
|
|
|
if (ctx.uses[mul_instr->definitions[0].tempId()]) {
|
|
|
|
|
if (op[0].isTemp())
|
|
|
|
|
ctx.uses[op[0].tempId()]++;
|
|
|
|
|
if (op[1].isTemp())
|
|
|
|
|
ctx.uses[op[1].tempId()]++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
bool neg[3] = {false, false, false};
|
|
|
|
|
bool abs[3] = {false, false, false};
|
|
|
|
|
unsigned omod = 0;
|
|
|
|
|
bool clamp = false;
|
2023-03-08 16:30:39 +01:00
|
|
|
bitarray8 opsel_lo = 0;
|
|
|
|
|
bitarray8 opsel_hi = 0;
|
2023-03-21 13:19:59 +01:00
|
|
|
bitarray8 opsel = 0;
|
2023-01-31 18:03:01 +01:00
|
|
|
unsigned mul_op_idx = (instr->isVOP3P() ? 3 : 1) - add_op_idx;
|
|
|
|
|
|
|
|
|
|
VALU_instruction& valu_mul = mul_instr->valu();
|
|
|
|
|
neg[0] = valu_mul.neg[0];
|
|
|
|
|
neg[1] = valu_mul.neg[1];
|
|
|
|
|
abs[0] = valu_mul.abs[0];
|
|
|
|
|
abs[1] = valu_mul.abs[1];
|
|
|
|
|
opsel_lo = valu_mul.opsel_lo & 0x3;
|
|
|
|
|
opsel_hi = valu_mul.opsel_hi & 0x3;
|
2023-03-21 13:19:59 +01:00
|
|
|
opsel = valu_mul.opsel & 0x3;
|
2023-01-31 18:03:01 +01:00
|
|
|
|
|
|
|
|
VALU_instruction& valu = instr->valu();
|
|
|
|
|
neg[2] = valu.neg[add_op_idx];
|
|
|
|
|
abs[2] = valu.abs[add_op_idx];
|
2023-03-08 16:30:39 +01:00
|
|
|
opsel_lo[2] = valu.opsel_lo[add_op_idx];
|
|
|
|
|
opsel_hi[2] = valu.opsel_hi[add_op_idx];
|
2023-03-21 13:19:59 +01:00
|
|
|
opsel[2] = valu.opsel[add_op_idx];
|
|
|
|
|
opsel[3] = valu.opsel[3];
|
2023-01-31 18:03:01 +01:00
|
|
|
omod = valu.omod;
|
|
|
|
|
clamp = valu.clamp;
|
|
|
|
|
/* abs of the multiplication result */
|
|
|
|
|
if (valu.abs[mul_op_idx]) {
|
|
|
|
|
neg[0] = false;
|
|
|
|
|
neg[1] = false;
|
|
|
|
|
abs[0] = true;
|
|
|
|
|
abs[1] = true;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2023-01-31 18:03:01 +01:00
|
|
|
/* neg of the multiplication result */
|
|
|
|
|
neg[1] ^= valu.neg[mul_op_idx];
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
|
2020-05-14 21:09:36 +01:00
|
|
|
if (instr->opcode == aco_opcode::v_sub_f32 || instr->opcode == aco_opcode::v_sub_f16)
|
2019-09-17 13:22:17 +02:00
|
|
|
neg[1 + add_op_idx] = neg[1 + add_op_idx] ^ true;
|
2020-05-14 21:09:36 +01:00
|
|
|
else if (instr->opcode == aco_opcode::v_subrev_f32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_subrev_f16)
|
2019-09-17 13:22:17 +02:00
|
|
|
neg[2 - add_op_idx] = neg[2 - add_op_idx] ^ true;
|
|
|
|
|
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
aco_ptr<Instruction> add_instr = std::move(instr);
|
2024-03-25 12:05:50 +01:00
|
|
|
aco_ptr<Instruction> mad;
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
if (add_instr->isVOP3P() || mul_instr->isVOP3P()) {
|
|
|
|
|
assert(!omod);
|
2023-03-21 13:19:59 +01:00
|
|
|
assert(!opsel);
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
|
|
|
|
|
aco_opcode mad_op = add_instr->definitions[0].bytes() == 2 ? aco_opcode::v_fma_mixlo_f16
|
|
|
|
|
: aco_opcode::v_fma_mix_f32;
|
2024-03-25 15:55:27 +01:00
|
|
|
mad.reset(create_instruction(mad_op, Format::VOP3P, 3, 1));
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
} else {
|
2023-01-31 18:03:01 +01:00
|
|
|
assert(!opsel_lo);
|
|
|
|
|
assert(!opsel_hi);
|
|
|
|
|
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
aco_opcode mad_op = emit_fma ? aco_opcode::v_fma_f32 : aco_opcode::v_mad_f32;
|
|
|
|
|
if (mul_instr->opcode == aco_opcode::v_mul_legacy_f32) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(emit_fma == (ctx.program->gfx_level >= GFX10_3));
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
mad_op = emit_fma ? aco_opcode::v_fma_legacy_f32 : aco_opcode::v_mad_legacy_f32;
|
|
|
|
|
} else if (mad16) {
|
2022-05-12 02:50:17 -04:00
|
|
|
mad_op = emit_fma ? (ctx.program->gfx_level == GFX8 ? aco_opcode::v_fma_legacy_f16
|
|
|
|
|
: aco_opcode::v_fma_f16)
|
|
|
|
|
: (ctx.program->gfx_level == GFX8 ? aco_opcode::v_mad_legacy_f16
|
|
|
|
|
: aco_opcode::v_mad_f16);
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
} else if (mad64) {
|
|
|
|
|
mad_op = aco_opcode::v_fma_f64;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 15:55:27 +01:00
|
|
|
mad.reset(create_instruction(mad_op, Format::VOP3, 3, 1));
|
2023-01-31 18:03:01 +01:00
|
|
|
}
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
|
2023-01-31 18:03:01 +01:00
|
|
|
for (unsigned i = 0; i < 3; i++) {
|
|
|
|
|
mad->operands[i] = op[i];
|
2024-03-25 12:05:50 +01:00
|
|
|
mad->valu().neg[i] = neg[i];
|
|
|
|
|
mad->valu().abs[i] = abs[i];
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2024-03-25 12:05:50 +01:00
|
|
|
mad->valu().omod = omod;
|
|
|
|
|
mad->valu().clamp = clamp;
|
|
|
|
|
mad->valu().opsel_lo = opsel_lo;
|
|
|
|
|
mad->valu().opsel_hi = opsel_hi;
|
|
|
|
|
mad->valu().opsel = opsel;
|
2023-01-31 18:03:01 +01:00
|
|
|
mad->definitions[0] = add_instr->definitions[0];
|
|
|
|
|
mad->definitions[0].setPrecise(add_instr->definitions[0].isPrecise() ||
|
|
|
|
|
mul_instr->definitions[0].isPrecise());
|
2023-05-09 20:24:52 +02:00
|
|
|
mad->pass_flags = add_instr->pass_flags;
|
2023-01-31 18:03:01 +01:00
|
|
|
|
|
|
|
|
instr = std::move(mad);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
/* mark this ssa_def to be re-checked for profitability and literals */
|
aco: combine add/mul as v_fma_mix into fma
fossil-db (Sienna Cichlid):
Totals from 7345 (5.44% of 134913) affected shaders:
CodeSize: 73840060 -> 73768936 (-0.10%); split: -0.10%, +0.00%
Instrs: 13701603 -> 13684183 (-0.13%); split: -0.13%, +0.00%
Latency: 185389373 -> 185306538 (-0.04%); split: -0.04%, +0.00%
InvThroughput: 33785020 -> 33757593 (-0.08%); split: -0.08%, +0.00%
VClause: 237337 -> 237338 (+0.00%)
SClause: 485728 -> 485720 (-0.00%)
Copies: 935900 -> 935279 (-0.07%); split: -0.07%, +0.00%
Branches: 480721 -> 480722 (+0.00%)
fossil-db (Navi):
Totals from 10649 (7.89% of 134913) affected shaders:
VGPRs: 756624 -> 756516 (-0.01%); split: -0.02%, +0.01%
CodeSize: 92156580 -> 91707900 (-0.49%); split: -0.49%, +0.00%
MaxWaves: 159402 -> 159476 (+0.05%); split: +0.07%, -0.02%
Instrs: 17155827 -> 17070449 (-0.50%); split: -0.50%, +0.00%
Latency: 246296456 -> 245487120 (-0.33%); split: -0.33%, +0.00%
InvThroughput: 41438159 -> 41117424 (-0.77%); split: -0.77%, +0.00%
VClause: 323790 -> 323867 (+0.02%); split: -0.00%, +0.03%
SClause: 612077 -> 612034 (-0.01%); split: -0.01%, +0.00%
Copies: 1103012 -> 1102775 (-0.02%); split: -0.03%, +0.01%
Branches: 555893 -> 555896 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 824372 -> 824378 (+0.00%)
PreVGPRs: 740390 -> 740363 (-0.00%); split: -0.01%, +0.01%
fossil-db (Vega):
Totals from 10950 (8.11% of 135048) affected shaders:
SGPRs: 1034528 -> 1034560 (+0.00%)
VGPRs: 794092 -> 794104 (+0.00%); split: -0.01%, +0.01%
CodeSize: 94409768 -> 93955568 (-0.48%); split: -0.48%, +0.00%
MaxWaves: 38950 -> 38939 (-0.03%); split: +0.00%, -0.03%
Instrs: 18162637 -> 18070934 (-0.50%); split: -0.51%, +0.00%
Latency: 291718455 -> 290772451 (-0.32%); split: -0.32%, +0.00%
InvThroughput: 109114674 -> 108489767 (-0.57%); split: -0.57%, +0.00%
VClause: 334498 -> 334579 (+0.02%); split: -0.01%, +0.03%
SClause: 628871 -> 628825 (-0.01%); split: -0.01%, +0.00%
Copies: 1674477 -> 1674850 (+0.02%); split: -0.02%, +0.04%
PreSGPRs: 834800 -> 834802 (+0.00%)
PreVGPRs: 750460 -> 750415 (-0.01%); split: -0.01%, +0.01%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14769>
2022-01-17 17:48:33 +00:00
|
|
|
ctx.mad_infos.emplace_back(std::move(add_instr), mul_instr->definitions[0].tempId());
|
2023-05-03 12:48:01 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_mad(ctx.mad_infos.size() - 1);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* v_mul_f32(v_cndmask_b32(0, 1.0, cond), a) -> v_cndmask_b32(0, a, cond) */
|
2024-09-13 20:06:46 +02:00
|
|
|
else if (((instr->opcode == aco_opcode::v_mul_f32 && !instr->definitions[0].isNaNPreserve() &&
|
|
|
|
|
!instr->definitions[0].isInfPreserve()) ||
|
|
|
|
|
(instr->opcode == aco_opcode::v_mul_legacy_f32 &&
|
|
|
|
|
!instr->definitions[0].isSZPreserve())) &&
|
2021-10-19 10:43:03 +01:00
|
|
|
!instr->usesModifiers() && !ctx.fp_mode.must_flush_denorms32) {
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (instr->operands[i].isTemp() && ctx.info[instr->operands[i].tempId()].is_b2f() &&
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()] == 1 && instr->operands[!i].isTemp() &&
|
|
|
|
|
instr->operands[!i].getTemp().type() == RegType::vgpr) {
|
|
|
|
|
ctx.uses[instr->operands[i].tempId()]--;
|
|
|
|
|
ctx.uses[ctx.info[instr->operands[i].tempId()].temp.id()]++;
|
|
|
|
|
|
2024-03-25 12:05:50 +01:00
|
|
|
aco_ptr<Instruction> new_instr{
|
2024-03-25 15:55:27 +01:00
|
|
|
create_instruction(aco_opcode::v_cndmask_b32, Format::VOP2, 3, 1)};
|
2021-07-13 11:22:46 +02:00
|
|
|
new_instr->operands[0] = Operand::zero();
|
2019-09-17 13:22:17 +02:00
|
|
|
new_instr->operands[1] = instr->operands[!i];
|
|
|
|
|
new_instr->operands[2] = Operand(ctx.info[instr->operands[i].tempId()].temp);
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
2023-05-09 20:24:52 +02:00
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
2021-09-16 20:50:29 +02:00
|
|
|
instr = std::move(new_instr);
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (instr->opcode == aco_opcode::v_or_b32 && ctx.program->gfx_level >= GFX9) {
|
2020-04-20 19:16:48 +01:00
|
|
|
if (combine_three_valu_op(ctx, instr, aco_opcode::s_or_b32, aco_opcode::v_or3_b32, "012",
|
|
|
|
|
1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::v_or_b32, aco_opcode::v_or3_b32,
|
|
|
|
|
"012", 1 | 2)) {
|
2020-08-12 14:35:15 +01:00
|
|
|
} else if (combine_add_or_then_and_lshl(ctx, instr)) {
|
2023-08-04 20:55:58 +02:00
|
|
|
} else if (combine_v_andor_not(ctx, instr)) {
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (instr->opcode == aco_opcode::v_xor_b32 && ctx.program->gfx_level >= GFX10) {
|
2020-06-04 14:36:00 +01:00
|
|
|
if (combine_three_valu_op(ctx, instr, aco_opcode::v_xor_b32, aco_opcode::v_xor3_b32, "012",
|
|
|
|
|
1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::s_xor_b32, aco_opcode::v_xor3_b32,
|
|
|
|
|
"012", 1 | 2)) {
|
2023-02-08 14:18:15 +01:00
|
|
|
} else if (combine_xor_not(ctx, instr)) {
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2023-02-08 14:18:15 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_not_b32 && ctx.program->gfx_level >= GFX10) {
|
|
|
|
|
combine_not_xor(ctx, instr);
|
2024-03-27 13:51:04 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_add_u16 && !instr->valu().clamp) {
|
2021-07-01 18:48:09 +02:00
|
|
|
combine_three_valu_op(
|
|
|
|
|
ctx, instr, aco_opcode::v_mul_lo_u16,
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.program->gfx_level == GFX8 ? aco_opcode::v_mad_legacy_u16 : aco_opcode::v_mad_u16,
|
2021-07-01 18:48:09 +02:00
|
|
|
"120", 1 | 2);
|
2024-03-27 13:51:04 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_add_u16_e64 && !instr->valu().clamp) {
|
2021-07-01 18:48:09 +02:00
|
|
|
combine_three_valu_op(ctx, instr, aco_opcode::v_mul_lo_u16_e64, aco_opcode::v_mad_u16, "120",
|
|
|
|
|
1 | 2);
|
2024-03-27 13:51:04 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_add_u32 && !instr->usesModifiers()) {
|
2020-04-02 17:41:36 +02:00
|
|
|
if (combine_add_sub_b2i(ctx, instr, aco_opcode::v_addc_co_u32, 1 | 2)) {
|
2020-11-11 18:42:35 +01:00
|
|
|
} else if (combine_add_bcnt(ctx, instr)) {
|
2020-06-05 17:36:29 +01:00
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::v_mul_u32_u24,
|
|
|
|
|
aco_opcode::v_mad_u32_u24, "120", 1 | 2)) {
|
2024-03-17 12:55:33 +01:00
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::v_mul_i32_i24,
|
|
|
|
|
aco_opcode::v_mad_i32_i24, "120", 1 | 2)) {
|
2024-03-27 13:51:04 +01:00
|
|
|
} else if (ctx.program->gfx_level >= GFX9) {
|
2020-04-02 17:41:36 +02:00
|
|
|
if (combine_three_valu_op(ctx, instr, aco_opcode::s_xor_b32, aco_opcode::v_xad_u32, "120",
|
|
|
|
|
1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::v_xor_b32, aco_opcode::v_xad_u32,
|
|
|
|
|
"120", 1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::s_add_i32, aco_opcode::v_add3_u32,
|
|
|
|
|
"012", 1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::s_add_u32, aco_opcode::v_add3_u32,
|
|
|
|
|
"012", 1 | 2)) {
|
|
|
|
|
} else if (combine_three_valu_op(ctx, instr, aco_opcode::v_add_u32, aco_opcode::v_add3_u32,
|
|
|
|
|
"012", 1 | 2)) {
|
2020-08-12 14:35:15 +01:00
|
|
|
} else if (combine_add_or_then_and_lshl(ctx, instr)) {
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2020-04-02 17:41:36 +02:00
|
|
|
}
|
2024-03-27 13:51:04 +01:00
|
|
|
} else if ((instr->opcode == aco_opcode::v_add_co_u32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_add_co_u32_e64) &&
|
|
|
|
|
!instr->usesModifiers()) {
|
2020-06-05 17:36:29 +01:00
|
|
|
bool carry_out = ctx.uses[instr->definitions[1].tempId()] > 0;
|
2020-11-11 18:42:35 +01:00
|
|
|
if (combine_add_sub_b2i(ctx, instr, aco_opcode::v_addc_co_u32, 1 | 2)) {
|
2020-06-05 17:36:29 +01:00
|
|
|
} else if (!carry_out && combine_add_bcnt(ctx, instr)) {
|
aco: optimize v_add+s_lshl to v_mad_u32_u24 on GFX6-8
This optimizes v_add(c, s_lshl(a, b)) to v_mad_u32_u24(a, 1<<b, c)
if 'b' is a constant (less than or equal to 6 to avoid creating
literals) and 'a' known to be a 16-bit or a 24-bit value.
On GFX9+, this is already optimized to v_lshl_add_u32.
fossils-db (Polaris10):
Totals from 1916 (1.36% of 140385) affected shaders:
SGPRs: 88322 -> 87780 (-0.61%); split: -0.66%, +0.05%
CodeSize: 7852668 -> 7851800 (-0.01%); split: -0.01%, +0.00%
Instrs: 1533965 -> 1530459 (-0.23%); split: -0.23%, +0.00%
Cycles: 57001852 -> 56983244 (-0.03%); split: -0.03%, +0.00%
VMEM: 372561 -> 371733 (-0.22%); split: +0.03%, -0.25%
SMEM: 108859 -> 103711 (-4.73%); split: +0.23%, -4.96%
VClause: 37231 -> 37204 (-0.07%)
SClause: 58116 -> 58086 (-0.05%); split: -0.06%, +0.01%
Copies: 199953 -> 199931 (-0.01%); split: -0.03%, +0.02%
Branches: 63478 -> 63477 (-0.00%)
PreSGPRs: 61818 -> 61816 (-0.00%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7673>
2020-11-16 18:01:32 +01:00
|
|
|
} else if (!carry_out && combine_three_valu_op(ctx, instr, aco_opcode::v_mul_u32_u24,
|
|
|
|
|
aco_opcode::v_mad_u32_u24, "120", 1 | 2)) {
|
2024-03-17 12:55:33 +01:00
|
|
|
} else if (!carry_out && combine_three_valu_op(ctx, instr, aco_opcode::v_mul_i32_i24,
|
|
|
|
|
aco_opcode::v_mad_i32_i24, "120", 1 | 2)) {
|
2021-09-09 08:38:41 +02:00
|
|
|
} else if (!carry_out && combine_add_lshl(ctx, instr, false)) {
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2020-04-02 17:41:36 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::v_sub_u32 || instr->opcode == aco_opcode::v_sub_co_u32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_sub_co_u32_e64) {
|
2021-09-28 17:11:28 +01:00
|
|
|
bool carry_out =
|
|
|
|
|
instr->opcode != aco_opcode::v_sub_u32 && ctx.uses[instr->definitions[1].tempId()] > 0;
|
2021-09-09 08:38:41 +02:00
|
|
|
if (combine_add_sub_b2i(ctx, instr, aco_opcode::v_subbrev_co_u32, 2)) {
|
|
|
|
|
} else if (!carry_out && combine_add_lshl(ctx, instr, true)) {
|
|
|
|
|
}
|
2020-04-02 17:41:36 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::v_subrev_u32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_subrev_co_u32 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_subrev_co_u32_e64) {
|
|
|
|
|
combine_add_sub_b2i(ctx, instr, aco_opcode::v_subbrev_co_u32, 1);
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (instr->opcode == aco_opcode::v_lshlrev_b32 && ctx.program->gfx_level >= GFX9) {
|
2019-09-17 13:22:17 +02:00
|
|
|
combine_three_valu_op(ctx, instr, aco_opcode::v_add_u32, aco_opcode::v_add_lshl_u32, "120",
|
|
|
|
|
2);
|
|
|
|
|
} else if ((instr->opcode == aco_opcode::s_add_u32 || instr->opcode == aco_opcode::s_add_i32) &&
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.program->gfx_level >= GFX9) {
|
2019-09-17 13:22:17 +02:00
|
|
|
combine_salu_lshl_add(ctx, instr);
|
2019-12-16 15:35:14 +00:00
|
|
|
} else if (instr->opcode == aco_opcode::s_not_b32 || instr->opcode == aco_opcode::s_not_b64) {
|
2022-08-20 22:55:45 +02:00
|
|
|
if (!combine_salu_not_bitwise(ctx, instr))
|
|
|
|
|
combine_inverse_comparison(ctx, instr);
|
2019-12-03 13:37:49 +00:00
|
|
|
} else if (instr->opcode == aco_opcode::s_and_b32 || instr->opcode == aco_opcode::s_or_b32 ||
|
|
|
|
|
instr->opcode == aco_opcode::s_and_b64 || instr->opcode == aco_opcode::s_or_b64) {
|
2024-05-29 16:16:33 +02:00
|
|
|
combine_salu_n2(ctx, instr);
|
2022-09-23 19:00:36 +02:00
|
|
|
} else if (instr->opcode == aco_opcode::s_abs_i32) {
|
|
|
|
|
combine_sabsdiff(ctx, instr);
|
aco: optimize v_and(a, v_subbrev_co(0, 0, vcc)) -> v_cndmask(0, a, vcc)
fossils-db (Vega10):
Totals from 7786 (5.70% of 136546) affected shaders:
SGPRs: 517778 -> 518626 (+0.16%); split: -0.01%, +0.17%
VGPRs: 488252 -> 488084 (-0.03%); split: -0.04%, +0.01%
CodeSize: 42282068 -> 42250152 (-0.08%); split: -0.16%, +0.09%
MaxWaves: 35697 -> 35716 (+0.05%); split: +0.06%, -0.01%
Instrs: 8319309 -> 8304792 (-0.17%); split: -0.18%, +0.00%
Cycles: 88619440 -> 88489636 (-0.15%); split: -0.16%, +0.01%
VMEM: 2788278 -> 2780431 (-0.28%); split: +0.06%, -0.35%
SMEM: 570364 -> 569370 (-0.17%); split: +0.12%, -0.30%
VClause: 144906 -> 144908 (+0.00%); split: -0.05%, +0.05%
SClause: 302143 -> 302055 (-0.03%); split: -0.04%, +0.01%
Copies: 579124 -> 578779 (-0.06%); split: -0.14%, +0.08%
PreSGPRs: 327695 -> 328845 (+0.35%); split: -0.00%, +0.35%
PreVGPRs: 434280 -> 433954 (-0.08%)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7438>
2020-11-03 18:50:32 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_and_b32) {
|
2025-02-20 16:47:27 +01:00
|
|
|
combine_v_andor_not(ctx, instr);
|
2020-06-16 18:04:21 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_fma_f32 || instr->opcode == aco_opcode::v_fma_f16) {
|
|
|
|
|
/* set existing v_fma_f32 with label_mad so we can create v_fmamk_f32/v_fmaak_f32.
|
|
|
|
|
* since ctx.uses[mad_info::mul_temp_id] is always 0, we don't have to worry about
|
|
|
|
|
* select_instruction() using mad_info::add_instr.
|
|
|
|
|
*/
|
|
|
|
|
ctx.mad_infos.emplace_back(nullptr, 0);
|
2023-05-03 12:48:01 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].set_mad(ctx.mad_infos.size() - 1);
|
2023-02-22 17:31:06 +01:00
|
|
|
} else if (instr->opcode == aco_opcode::v_med3_f32 || instr->opcode == aco_opcode::v_med3_f16) {
|
2023-12-01 16:20:38 +00:00
|
|
|
/* Optimize v_med3 to v_add so that it can be dual issued on GFX11. We start with v_med3 in
|
|
|
|
|
* case omod can be applied.
|
|
|
|
|
*/
|
2023-02-22 17:31:06 +01:00
|
|
|
unsigned idx;
|
|
|
|
|
if (detect_clamp(instr.get(), &idx)) {
|
|
|
|
|
instr->format = asVOP3(Format::VOP2);
|
|
|
|
|
instr->operands[0] = instr->operands[idx];
|
|
|
|
|
instr->operands[1] = Operand::zero();
|
|
|
|
|
instr->opcode =
|
|
|
|
|
instr->opcode == aco_opcode::v_med3_f32 ? aco_opcode::v_add_f32 : aco_opcode::v_add_f16;
|
|
|
|
|
instr->valu().clamp = true;
|
|
|
|
|
instr->valu().abs = (uint8_t)instr->valu().abs[idx];
|
|
|
|
|
instr->valu().neg = (uint8_t)instr->valu().neg[idx];
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
aco_opcode min, max, min3, max3, med3, minmax;
|
2019-09-17 13:22:17 +02:00
|
|
|
bool some_gfx9_only;
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
if (get_minmax_info(instr->opcode, &min, &max, &min3, &max3, &med3, &minmax,
|
|
|
|
|
&some_gfx9_only) &&
|
2022-05-12 02:50:17 -04:00
|
|
|
(!some_gfx9_only || ctx.program->gfx_level >= GFX9)) {
|
2019-11-22 20:32:11 +00:00
|
|
|
if (combine_minmax(ctx, instr, instr->opcode == min ? max : min,
|
aco: use v_minmax/v_maxmin opcodes
fossil-db (gfx1100):
Totals from 29868 (22.12% of 135032) affected shaders:
MaxWaves: 741336 -> 741344 (+0.00%)
Instrs: 34624902 -> 34539766 (-0.25%); split: -0.25%, +0.00%
CodeSize: 187196804 -> 187192100 (-0.00%); split: -0.01%, +0.01%
VGPRs: 1816860 -> 1816788 (-0.00%); split: -0.01%, +0.01%
Latency: 502597202 -> 502245627 (-0.07%); split: -0.08%, +0.01%
InvThroughput: 84813176 -> 84586122 (-0.27%); split: -0.28%, +0.01%
VClause: 633826 -> 633749 (-0.01%); split: -0.02%, +0.01%
SClause: 1317738 -> 1317047 (-0.05%); split: -0.06%, +0.01%
Copies: 2130610 -> 2130954 (+0.02%); split: -0.03%, +0.05%
Branches: 766093 -> 765969 (-0.02%); split: -0.02%, +0.00%
PreSGPRs: 1630250 -> 1630034 (-0.01%); split: -0.02%, +0.00%
PreVGPRs: 1590777 -> 1590664 (-0.01%); split: -0.01%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19933>
2022-11-16 17:42:20 +00:00
|
|
|
instr->opcode == min ? min3 : max3, minmax)) {
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
combine_clamp(ctx, instr, min, max, med3);
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
struct remat_entry {
|
|
|
|
|
Instruction* instr;
|
|
|
|
|
uint32_t block;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
|
is_constant(Instruction* instr)
|
|
|
|
|
{
|
|
|
|
|
if (instr->opcode != aco_opcode::p_parallelcopy || instr->operands.size() != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return instr->operands[0].isConstant() && instr->definitions[0].isTemp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
remat_constants_instr(opt_ctx& ctx, aco::map<Temp, remat_entry>& constants, Instruction* instr,
|
|
|
|
|
uint32_t block_idx)
|
|
|
|
|
{
|
|
|
|
|
for (Operand& op : instr->operands) {
|
|
|
|
|
if (!op.isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
auto it = constants.find(op.getTemp());
|
|
|
|
|
if (it == constants.end())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* Check if we already emitted the same constant in this block. */
|
|
|
|
|
if (it->second.block != block_idx) {
|
|
|
|
|
/* Rematerialize the constant. */
|
|
|
|
|
Builder bld(ctx.program, &ctx.instructions);
|
|
|
|
|
Operand const_op = it->second.instr->operands[0];
|
|
|
|
|
it->second.instr = bld.copy(bld.def(op.regClass()), const_op);
|
|
|
|
|
it->second.block = block_idx;
|
|
|
|
|
ctx.uses.push_back(0);
|
|
|
|
|
ctx.info.push_back(ctx.info[op.tempId()]);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[it->second.instr->definitions[0].tempId()].parent_instr = it->second.instr;
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Use the rematerialized constant and update information about latest use. */
|
|
|
|
|
if (op.getTemp() != it->second.instr->definitions[0].getTemp()) {
|
|
|
|
|
ctx.uses[op.tempId()]--;
|
|
|
|
|
op.setTemp(it->second.instr->definitions[0].getTemp());
|
|
|
|
|
ctx.uses[op.tempId()]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This pass implements a simple constant rematerialization.
|
|
|
|
|
* As common subexpression elimination (CSE) might increase the live-ranges
|
|
|
|
|
* of loaded constants over large distances, this pass splits the live-ranges
|
|
|
|
|
* again by re-emitting constants in every basic block.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
rematerialize_constants(opt_ctx& ctx)
|
|
|
|
|
{
|
|
|
|
|
aco::monotonic_buffer_resource memory(1024);
|
|
|
|
|
aco::map<Temp, remat_entry> constants(memory);
|
|
|
|
|
|
|
|
|
|
for (Block& block : ctx.program->blocks) {
|
|
|
|
|
if (block.logical_idom == -1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (block.logical_idom == (int)block.index)
|
|
|
|
|
constants.clear();
|
|
|
|
|
|
|
|
|
|
ctx.instructions.reserve(block.instructions.size());
|
|
|
|
|
|
|
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions) {
|
|
|
|
|
if (is_dead(ctx.uses, instr.get()))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (is_constant(instr.get())) {
|
|
|
|
|
Temp tmp = instr->definitions[0].getTemp();
|
|
|
|
|
constants[tmp] = {instr.get(), block.index};
|
|
|
|
|
} else if (!is_phi(instr)) {
|
|
|
|
|
remat_constants_instr(ctx, constants, instr.get(), block.index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.instructions.emplace_back(instr.release());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block.instructions = std::move(ctx.instructions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
bool
|
|
|
|
|
to_uniform_bool_instr(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
2021-08-25 12:13:39 +02:00
|
|
|
/* Check every operand to make sure they are suitable. */
|
|
|
|
|
for (Operand& op : instr->operands) {
|
|
|
|
|
if (!op.isTemp())
|
|
|
|
|
return false;
|
|
|
|
|
if (!ctx.info[op.tempId()].is_uniform_bool() && !ctx.info[op.tempId()].is_uniform_bitwise())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
switch (instr->opcode) {
|
|
|
|
|
case aco_opcode::s_and_b32:
|
|
|
|
|
case aco_opcode::s_and_b64: instr->opcode = aco_opcode::s_and_b32; break;
|
|
|
|
|
case aco_opcode::s_or_b32:
|
|
|
|
|
case aco_opcode::s_or_b64: instr->opcode = aco_opcode::s_or_b32; break;
|
|
|
|
|
case aco_opcode::s_xor_b32:
|
|
|
|
|
case aco_opcode::s_xor_b64: instr->opcode = aco_opcode::s_absdiff_i32; break;
|
2025-07-15 16:26:05 +01:00
|
|
|
case aco_opcode::s_not_b32:
|
|
|
|
|
case aco_opcode::s_not_b64: {
|
|
|
|
|
aco_ptr<Instruction> new_instr{
|
|
|
|
|
create_instruction(aco_opcode::s_absdiff_i32, Format::SOP2, 2, 2)};
|
|
|
|
|
new_instr->operands[0] = instr->operands[0];
|
|
|
|
|
new_instr->operands[1] = Operand::c32(1);
|
|
|
|
|
new_instr->definitions[0] = instr->definitions[0];
|
|
|
|
|
new_instr->definitions[1] = instr->definitions[1];
|
|
|
|
|
new_instr->pass_flags = instr->pass_flags;
|
|
|
|
|
instr = std::move(new_instr);
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
|
|
|
|
ctx.info[instr->definitions[1].tempId()].parent_instr = instr.get();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-01-16 19:32:31 +01:00
|
|
|
default:
|
|
|
|
|
/* Don't transform other instructions. They are very unlikely to appear here. */
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Operand& op : instr->operands) {
|
2025-07-15 16:26:05 +01:00
|
|
|
if (!op.isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
ctx.uses[op.tempId()]--;
|
|
|
|
|
|
|
|
|
|
if (ctx.info[op.tempId()].is_uniform_bool()) {
|
|
|
|
|
/* Just use the uniform boolean temp. */
|
|
|
|
|
op.setTemp(ctx.info[op.tempId()].temp);
|
|
|
|
|
} else if (ctx.info[op.tempId()].is_uniform_bitwise()) {
|
|
|
|
|
/* Use the SCC definition of the predecessor instruction.
|
|
|
|
|
* This allows the predecessor to get picked up by the same optimization (if it has no
|
|
|
|
|
* divergent users), and it also makes sure that the current instruction will keep working
|
|
|
|
|
* even if the predecessor won't be transformed.
|
|
|
|
|
*/
|
2024-07-23 17:49:32 +02:00
|
|
|
Instruction* pred_instr = ctx.info[op.tempId()].parent_instr;
|
2020-01-16 19:32:31 +01:00
|
|
|
assert(pred_instr->definitions.size() >= 2);
|
|
|
|
|
assert(pred_instr->definitions[1].isFixed() &&
|
|
|
|
|
pred_instr->definitions[1].physReg() == scc);
|
|
|
|
|
op.setTemp(pred_instr->definitions[1].getTemp());
|
|
|
|
|
} else {
|
2025-07-23 09:17:35 +02:00
|
|
|
UNREACHABLE("Invalid operand on uniform bitwise instruction.");
|
2020-01-16 19:32:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.uses[op.tempId()]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instr->definitions[0].setTemp(Temp(instr->definitions[0].tempId(), s1));
|
2024-07-28 13:55:29 +02:00
|
|
|
ctx.program->temp_rc[instr->definitions[0].tempId()] = s1;
|
2025-07-15 16:26:05 +01:00
|
|
|
assert(!instr->operands[0].isTemp() || instr->operands[0].regClass() == s1);
|
|
|
|
|
assert(!instr->operands[1].isTemp() || instr->operands[1].regClass() == s1);
|
2020-01-16 19:32:31 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
select_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
const uint32_t threshold = 4;
|
|
|
|
|
|
2019-12-16 13:30:10 +00:00
|
|
|
if (is_dead(ctx.uses, instr.get())) {
|
2019-09-17 13:22:17 +02:00
|
|
|
instr.reset();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 21:20:10 +00:00
|
|
|
/* convert split_vector into a copy or extract_vector if only one definition is ever used */
|
2019-09-17 13:22:17 +02:00
|
|
|
if (instr->opcode == aco_opcode::p_split_vector) {
|
|
|
|
|
unsigned num_used = 0;
|
|
|
|
|
unsigned idx = 0;
|
2020-04-10 13:09:54 +01:00
|
|
|
unsigned split_offset = 0;
|
|
|
|
|
for (unsigned i = 0, offset = 0; i < instr->definitions.size();
|
|
|
|
|
offset += instr->definitions[i++].bytes()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
if (ctx.uses[instr->definitions[i].tempId()]) {
|
|
|
|
|
num_used++;
|
|
|
|
|
idx = i;
|
2020-04-10 13:09:54 +01:00
|
|
|
split_offset = offset;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-09 21:20:10 +00:00
|
|
|
bool done = false;
|
2024-07-30 11:31:15 +02:00
|
|
|
Instruction* vec = ctx.info[instr->operands[0].tempId()].parent_instr;
|
|
|
|
|
if (num_used == 1 && vec->opcode == aco_opcode::p_create_vector &&
|
2019-12-09 21:20:10 +00:00
|
|
|
ctx.uses[instr->operands[0].tempId()] == 1) {
|
|
|
|
|
|
|
|
|
|
unsigned off = 0;
|
|
|
|
|
Operand op;
|
|
|
|
|
for (Operand& vec_op : vec->operands) {
|
2020-04-10 13:09:54 +01:00
|
|
|
if (off == split_offset) {
|
2019-12-09 21:20:10 +00:00
|
|
|
op = vec_op;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-04-10 13:09:54 +01:00
|
|
|
off += vec_op.bytes();
|
2019-12-09 21:20:10 +00:00
|
|
|
}
|
2020-04-10 13:09:54 +01:00
|
|
|
if (off != instr->operands[0].bytes() && op.bytes() == instr->definitions[idx].bytes()) {
|
2019-12-09 21:20:10 +00:00
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
|
|
|
|
for (Operand& vec_op : vec->operands) {
|
|
|
|
|
if (vec_op.isTemp())
|
|
|
|
|
ctx.uses[vec_op.tempId()]--;
|
|
|
|
|
}
|
|
|
|
|
if (op.isTemp())
|
|
|
|
|
ctx.uses[op.tempId()]++;
|
|
|
|
|
|
2024-06-06 16:53:09 +01:00
|
|
|
aco_ptr<Instruction> copy{
|
|
|
|
|
create_instruction(aco_opcode::p_parallelcopy, Format::PSEUDO, 1, 1)};
|
|
|
|
|
copy->operands[0] = op;
|
|
|
|
|
copy->definitions[0] = instr->definitions[idx];
|
|
|
|
|
instr = std::move(copy);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-12-09 21:20:10 +00:00
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 13:09:54 +01:00
|
|
|
if (!done && num_used == 1 &&
|
|
|
|
|
instr->operands[0].bytes() % instr->definitions[idx].bytes() == 0 &&
|
|
|
|
|
split_offset % instr->definitions[idx].bytes() == 0) {
|
2024-03-25 15:55:27 +01:00
|
|
|
aco_ptr<Instruction> extract{
|
|
|
|
|
create_instruction(aco_opcode::p_extract_vector, Format::PSEUDO, 2, 1)};
|
2019-09-17 13:22:17 +02:00
|
|
|
extract->operands[0] = instr->operands[0];
|
2021-07-13 11:22:46 +02:00
|
|
|
extract->operands[1] =
|
|
|
|
|
Operand::c32((uint32_t)split_offset / instr->definitions[idx].bytes());
|
2019-09-17 13:22:17 +02:00
|
|
|
extract->definitions[0] = instr->definitions[idx];
|
2021-09-16 20:50:29 +02:00
|
|
|
instr = std::move(extract);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 15:18:38 +00:00
|
|
|
mad_info* mad_info = NULL;
|
2020-05-15 14:03:15 +01:00
|
|
|
if (!instr->definitions.empty() && ctx.info[instr->definitions[0].tempId()].is_mad()) {
|
2023-05-03 12:48:01 +02:00
|
|
|
mad_info = &ctx.mad_infos[ctx.info[instr->definitions[0].tempId()].val];
|
2019-11-22 15:18:38 +00:00
|
|
|
/* re-check mad instructions */
|
aco: optimize 32-bit extracts and inserts using SDWA
Still need to use dst_u=preserve field to optimize packs
fossil-db (Sienna Cichlid):
Totals from 15974 (10.66% of 149839) affected shaders:
VGPRs: 1009064 -> 1008968 (-0.01%); split: -0.03%, +0.02%
SpillSGPRs: 7959 -> 7964 (+0.06%)
CodeSize: 101716436 -> 101159568 (-0.55%); split: -0.55%, +0.01%
MaxWaves: 284464 -> 284490 (+0.01%); split: +0.02%, -0.01%
Instrs: 19334216 -> 19224241 (-0.57%); split: -0.57%, +0.00%
Latency: 375465295 -> 375230478 (-0.06%); split: -0.14%, +0.08%
InvThroughput: 79006105 -> 78860705 (-0.18%); split: -0.25%, +0.07%
fossil-db (Polaris):
Totals from 11369 (7.51% of 151365) affected shaders:
SGPRs: 787920 -> 787680 (-0.03%); split: -0.04%, +0.01%
VGPRs: 681056 -> 681040 (-0.00%); split: -0.01%, +0.00%
CodeSize: 68127288 -> 67664120 (-0.68%); split: -0.69%, +0.01%
MaxWaves: 54370 -> 54371 (+0.00%)
Instrs: 13294638 -> 13214109 (-0.61%); split: -0.62%, +0.01%
Latency: 373515759 -> 373214571 (-0.08%); split: -0.11%, +0.03%
InvThroughput: 166529524 -> 166275291 (-0.15%); split: -0.20%, +0.05%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3151>
2020-08-12 14:23:56 +01:00
|
|
|
if (ctx.uses[mad_info->mul_temp_id] && mad_info->add_instr) {
|
2019-11-22 15:18:38 +00:00
|
|
|
ctx.uses[mad_info->mul_temp_id]++;
|
2019-11-20 19:09:25 +00:00
|
|
|
if (instr->operands[0].isTemp())
|
|
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
|
|
|
|
if (instr->operands[1].isTemp())
|
|
|
|
|
ctx.uses[instr->operands[1].tempId()]--;
|
2019-11-22 15:18:38 +00:00
|
|
|
instr.swap(mad_info->add_instr);
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2019-11-22 15:18:38 +00:00
|
|
|
mad_info = NULL;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
/* Mark SCC needed, so the uniform boolean transformation won't swap the definitions
|
|
|
|
|
* when it isn't beneficial */
|
2020-11-18 21:28:09 +01:00
|
|
|
if (instr->isBranch() && instr->operands.size() && instr->operands[0].isTemp() &&
|
|
|
|
|
instr->operands[0].isFixed() && instr->operands[0].physReg() == scc) {
|
2020-01-16 19:32:31 +01:00
|
|
|
ctx.info[instr->operands[0].tempId()].set_scc_needed();
|
|
|
|
|
return;
|
|
|
|
|
} else if ((instr->opcode == aco_opcode::s_cselect_b64 ||
|
|
|
|
|
instr->opcode == aco_opcode::s_cselect_b32) &&
|
|
|
|
|
instr->operands[2].isTemp()) {
|
|
|
|
|
ctx.info[instr->operands[2].tempId()].set_scc_needed();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* check for literals */
|
2019-11-22 13:43:39 +00:00
|
|
|
if (!instr->isSALU() && !instr->isVALU())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-01-16 19:32:31 +01:00
|
|
|
/* Transform uniform bitwise boolean operations to 32-bit when there are no divergent uses. */
|
|
|
|
|
if (instr->definitions.size() && ctx.uses[instr->definitions[0].tempId()] == 0 &&
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].is_uniform_bitwise()) {
|
|
|
|
|
bool transform_done = to_uniform_bool_instr(ctx, instr);
|
|
|
|
|
|
|
|
|
|
if (transform_done && !ctx.info[instr->definitions[1].tempId()].is_scc_needed()) {
|
|
|
|
|
/* Swap the two definition IDs in order to avoid overusing the SCC.
|
|
|
|
|
* This reduces extra moves generated by RA. */
|
|
|
|
|
uint32_t def0_id = instr->definitions[0].getTemp().id();
|
|
|
|
|
uint32_t def1_id = instr->definitions[1].getTemp().id();
|
|
|
|
|
instr->definitions[0].setTemp(Temp(def1_id, s1));
|
|
|
|
|
instr->definitions[1].setTemp(Temp(def0_id, s1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-24 12:25:23 +02:00
|
|
|
/* This optimization is done late in order to be able to apply otherwise
|
|
|
|
|
* unsafe optimizations such as the inverse comparison optimization.
|
|
|
|
|
*/
|
|
|
|
|
if (instr->opcode == aco_opcode::s_and_b32 || instr->opcode == aco_opcode::s_and_b64) {
|
|
|
|
|
if (instr->operands[0].isTemp() && fixed_to_exec(instr->operands[1]) &&
|
|
|
|
|
ctx.uses[instr->operands[0].tempId()] == 1 &&
|
|
|
|
|
ctx.uses[instr->definitions[1].tempId()] == 0 &&
|
2025-07-07 17:57:20 +01:00
|
|
|
can_eliminate_and_exec(ctx, instr->operands[0].getTemp(), instr->pass_flags, true)) {
|
2022-08-24 12:25:23 +02:00
|
|
|
ctx.uses[instr->operands[0].tempId()]--;
|
2024-07-24 12:28:36 +02:00
|
|
|
Instruction* op_instr = ctx.info[instr->operands[0].tempId()].parent_instr;
|
2025-07-07 17:57:20 +01:00
|
|
|
|
|
|
|
|
if (op_instr->opcode == aco_opcode::s_cselect_b32 ||
|
|
|
|
|
op_instr->opcode == aco_opcode::s_cselect_b64) {
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
if (op_instr->operands[i].constantEquals(-1))
|
|
|
|
|
op_instr->operands[i] = instr->operands[1];
|
|
|
|
|
}
|
|
|
|
|
ctx.info[op_instr->definitions[0].tempId()].label &= label_uniform_bool;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-24 12:28:36 +02:00
|
|
|
op_instr->definitions[0].setTemp(instr->definitions[0].getTemp());
|
|
|
|
|
ctx.info[op_instr->definitions[0].tempId()].parent_instr = op_instr;
|
2022-08-24 12:25:23 +02:00
|
|
|
instr.reset();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 15:33:18 +01:00
|
|
|
/* Combine DPP copies into VALU. This should be done after creating MAD/FMA. */
|
2023-04-23 14:55:17 +02:00
|
|
|
if (instr->isVALU() && !instr->isDPP()) {
|
2020-06-30 15:33:18 +01:00
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
if (!instr->operands[i].isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
ssa_info info = ctx.info[instr->operands[i].tempId()];
|
|
|
|
|
|
2025-05-09 11:24:02 +02:00
|
|
|
if (!info.parent_instr->isDPP() || info.parent_instr->opcode != aco_opcode::v_mov_b32 ||
|
2024-07-23 17:49:32 +02:00
|
|
|
info.parent_instr->pass_flags != instr->pass_flags)
|
2023-02-08 16:37:44 +00:00
|
|
|
continue;
|
|
|
|
|
|
2023-04-25 20:56:18 +02:00
|
|
|
/* We won't eliminate the DPP mov if the operand is used twice */
|
|
|
|
|
bool op_used_twice = false;
|
|
|
|
|
for (unsigned j = 0; j < instr->operands.size(); j++)
|
|
|
|
|
op_used_twice |= i != j && instr->operands[i] == instr->operands[j];
|
|
|
|
|
if (op_used_twice)
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-04-23 14:55:17 +02:00
|
|
|
if (i != 0) {
|
|
|
|
|
if (!can_swap_operands(instr, &instr->opcode, 0, i))
|
|
|
|
|
continue;
|
2023-05-18 10:54:45 +02:00
|
|
|
instr->valu().swapOperands(0, i);
|
2023-04-23 14:55:17 +02:00
|
|
|
}
|
2023-02-08 16:37:44 +00:00
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
bool dpp8 = info.parent_instr->isDPP8();
|
2024-07-15 19:07:21 +02:00
|
|
|
if (!can_use_DPP(ctx.program->gfx_level, instr, dpp8))
|
2023-02-08 16:37:44 +00:00
|
|
|
continue;
|
|
|
|
|
|
2023-05-16 17:26:21 +02:00
|
|
|
bool input_mods = can_use_input_modifiers(ctx.program->gfx_level, instr->opcode, 0) &&
|
2025-05-16 12:20:49 +02:00
|
|
|
get_operand_type(instr, 0).bit_size == 32;
|
2024-07-23 17:49:32 +02:00
|
|
|
bool mov_uses_mods = info.parent_instr->valu().neg[0] || info.parent_instr->valu().abs[0];
|
2023-04-23 14:55:17 +02:00
|
|
|
if (((dpp8 && ctx.program->gfx_level < GFX11) || !input_mods) && mov_uses_mods)
|
2023-02-08 16:37:44 +00:00
|
|
|
continue;
|
|
|
|
|
|
2023-04-23 14:55:17 +02:00
|
|
|
convert_to_DPP(ctx.program->gfx_level, instr, dpp8);
|
2023-03-23 13:10:58 +01:00
|
|
|
|
2023-02-08 16:37:44 +00:00
|
|
|
if (dpp8) {
|
|
|
|
|
DPP8_instruction* dpp = &instr->dpp8();
|
2024-07-23 17:49:32 +02:00
|
|
|
dpp->lane_sel = info.parent_instr->dpp8().lane_sel;
|
|
|
|
|
dpp->fetch_inactive = info.parent_instr->dpp8().fetch_inactive;
|
2023-04-23 14:55:17 +02:00
|
|
|
if (mov_uses_mods)
|
|
|
|
|
instr->format = asVOP3(instr->format);
|
2023-02-08 16:37:44 +00:00
|
|
|
} else {
|
|
|
|
|
DPP16_instruction* dpp = &instr->dpp16();
|
2024-07-15 19:07:21 +02:00
|
|
|
/* anything else doesn't make sense in SSA */
|
2024-07-23 17:49:32 +02:00
|
|
|
assert(info.parent_instr->dpp16().row_mask == 0xf &&
|
|
|
|
|
info.parent_instr->dpp16().bank_mask == 0xf);
|
|
|
|
|
dpp->dpp_ctrl = info.parent_instr->dpp16().dpp_ctrl;
|
|
|
|
|
dpp->bound_ctrl = info.parent_instr->dpp16().bound_ctrl;
|
|
|
|
|
dpp->fetch_inactive = info.parent_instr->dpp16().fetch_inactive;
|
2020-06-30 15:33:18 +01:00
|
|
|
}
|
2023-02-08 16:37:44 +00:00
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
instr->valu().neg[0] ^= info.parent_instr->valu().neg[0] && !instr->valu().abs[0];
|
|
|
|
|
instr->valu().abs[0] |= info.parent_instr->valu().abs[0];
|
2023-04-23 14:55:17 +02:00
|
|
|
|
2024-07-23 17:49:32 +02:00
|
|
|
if (--ctx.uses[info.parent_instr->definitions[0].tempId()])
|
|
|
|
|
ctx.uses[info.parent_instr->operands[0].tempId()]++;
|
|
|
|
|
instr->operands[0].setTemp(info.parent_instr->operands[0].getTemp());
|
2024-07-24 12:28:36 +02:00
|
|
|
for (const Definition& def : instr->definitions)
|
|
|
|
|
ctx.info[def.tempId()].parent_instr = instr.get();
|
2023-02-08 16:37:44 +00:00
|
|
|
break;
|
2020-06-30 15:33:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 15:25:17 +02:00
|
|
|
/* Use v_fma_mix for f2f32/f2f16 if it has higher throughput.
|
|
|
|
|
* Do this late to not disturb other optimizations.
|
|
|
|
|
*/
|
|
|
|
|
if ((instr->opcode == aco_opcode::v_cvt_f32_f16 || instr->opcode == aco_opcode::v_cvt_f16_f32) &&
|
|
|
|
|
ctx.program->gfx_level >= GFX11 && ctx.program->wave_size == 64 && !instr->valu().omod &&
|
|
|
|
|
!instr->isDPP()) {
|
|
|
|
|
bool is_f2f16 = instr->opcode == aco_opcode::v_cvt_f16_f32;
|
2024-03-25 15:55:27 +01:00
|
|
|
Instruction* fma = create_instruction(
|
2023-04-20 15:25:17 +02:00
|
|
|
is_f2f16 ? aco_opcode::v_fma_mixlo_f16 : aco_opcode::v_fma_mix_f32, Format::VOP3P, 3, 1);
|
|
|
|
|
fma->definitions[0] = instr->definitions[0];
|
|
|
|
|
fma->operands[0] = instr->operands[0];
|
|
|
|
|
fma->valu().opsel_hi[0] = !is_f2f16;
|
|
|
|
|
fma->valu().opsel_lo[0] = instr->valu().opsel[0];
|
|
|
|
|
fma->valu().clamp = instr->valu().clamp;
|
|
|
|
|
fma->valu().abs[0] = instr->valu().abs[0];
|
|
|
|
|
fma->valu().neg[0] = instr->valu().neg[0];
|
|
|
|
|
fma->operands[1] = Operand::c32(fui(1.0f));
|
|
|
|
|
fma->operands[2] = Operand::zero();
|
|
|
|
|
fma->valu().neg[2] = true;
|
|
|
|
|
instr.reset(fma);
|
|
|
|
|
ctx.info[instr->definitions[0].tempId()].label = 0;
|
2024-07-24 12:28:36 +02:00
|
|
|
ctx.info[instr->definitions[0].tempId()].parent_instr = instr.get();
|
2023-04-20 15:25:17 +02:00
|
|
|
}
|
|
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
/* Check operands for whether we can apply constants or literals. */
|
|
|
|
|
if (std::none_of(instr->operands.begin(), instr->operands.end(),
|
|
|
|
|
[&](const Operand& op)
|
|
|
|
|
{
|
|
|
|
|
if (!op.isTemp() || op.isFixed())
|
|
|
|
|
return false;
|
|
|
|
|
auto& temp_info = ctx.info[op.tempId()];
|
|
|
|
|
return temp_info.is_constant_or_literal(op.size() * 32);
|
|
|
|
|
}))
|
2020-01-24 17:37:11 +00:00
|
|
|
return;
|
2019-11-22 13:43:39 +00:00
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
alu_opt_info input_info;
|
|
|
|
|
if (!alu_opt_gather_info(ctx, instr.get(), input_info))
|
|
|
|
|
return;
|
2020-01-23 20:03:40 +00:00
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
unsigned literal_mask = 0;
|
|
|
|
|
for (unsigned i = 0; i < input_info.operands.size(); i++) {
|
|
|
|
|
Operand op = input_info.operands[i].op;
|
|
|
|
|
if (!op.isTemp() || op.isFixed())
|
2019-11-22 13:43:39 +00:00
|
|
|
continue;
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
auto& temp_info = ctx.info[op.tempId()];
|
|
|
|
|
if (temp_info.is_constant_or_literal(op.size() * 32))
|
|
|
|
|
literal_mask |= BITFIELD_BIT(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alu_opt_info lit_info;
|
|
|
|
|
bool force_create = false;
|
|
|
|
|
unsigned lit_uses = threshold;
|
|
|
|
|
for (unsigned sub_mask = (~literal_mask + 1) & literal_mask; sub_mask;
|
|
|
|
|
sub_mask = ((sub_mask | ~literal_mask) + 1) & literal_mask) {
|
|
|
|
|
alu_opt_info candidate = input_info;
|
|
|
|
|
unsigned candidate_uses = UINT32_MAX;
|
|
|
|
|
u_foreach_bit (i, sub_mask) {
|
|
|
|
|
uint32_t tmpid = candidate.operands[i].op.tempId();
|
|
|
|
|
candidate.operands[i].op = Operand::literal32(ctx.info[tmpid].val);
|
|
|
|
|
candidate_uses = MIN2(candidate_uses, ctx.uses[tmpid]);
|
|
|
|
|
}
|
|
|
|
|
if (!alu_opt_info_is_valid(ctx, candidate))
|
2019-11-22 13:43:39 +00:00
|
|
|
continue;
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
|
|
|
|
|
switch (candidate.opcode) {
|
|
|
|
|
case aco_opcode::v_fmaak_f32:
|
|
|
|
|
case aco_opcode::v_fmaak_f16:
|
|
|
|
|
case aco_opcode::v_madak_f32:
|
|
|
|
|
case aco_opcode::v_madak_f16:
|
|
|
|
|
/* This instruction won't be able to use fmac, so fmaak doesn't regress code size. */
|
|
|
|
|
force_create = true;
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2019-11-22 13:43:39 +00:00
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
if (!force_create && util_bitcount(sub_mask) <= 1 && candidate_uses >= lit_uses)
|
2019-11-22 13:43:39 +00:00
|
|
|
continue;
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
lit_info = candidate;
|
|
|
|
|
lit_uses = candidate_uses;
|
2019-11-22 13:43:39 +00:00
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
if (util_bitcount(sub_mask) > 1) {
|
|
|
|
|
force_create = true;
|
|
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
if (!lit_info.operands.size())
|
2019-11-22 13:43:39 +00:00
|
|
|
return;
|
|
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
for (const auto& op_info : lit_info.operands) {
|
|
|
|
|
if (op_info.op.isTemp())
|
|
|
|
|
ctx.uses[op_info.op.tempId()]++;
|
|
|
|
|
}
|
|
|
|
|
for (Operand op : instr->operands) {
|
|
|
|
|
if (op.isTemp())
|
|
|
|
|
decrease_and_dce(ctx, op.getTemp());
|
2019-11-22 13:43:39 +00:00
|
|
|
}
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
if (force_create || lit_uses == 1)
|
|
|
|
|
instr.reset(alu_opt_info_to_instr(ctx, lit_info, instr.release()));
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-17 22:14:30 +02:00
|
|
|
static aco_opcode
|
|
|
|
|
sopk_opcode_for_sopc(aco_opcode opcode)
|
|
|
|
|
{
|
|
|
|
|
#define CTOK(op) \
|
|
|
|
|
case aco_opcode::s_cmp_##op##_i32: return aco_opcode::s_cmpk_##op##_i32; \
|
|
|
|
|
case aco_opcode::s_cmp_##op##_u32: return aco_opcode::s_cmpk_##op##_u32;
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
CTOK(eq)
|
|
|
|
|
CTOK(lg)
|
|
|
|
|
CTOK(gt)
|
|
|
|
|
CTOK(ge)
|
|
|
|
|
CTOK(lt)
|
|
|
|
|
CTOK(le)
|
|
|
|
|
default: return aco_opcode::num_opcodes;
|
|
|
|
|
}
|
|
|
|
|
#undef CTOK
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
sopc_is_signed(aco_opcode opcode)
|
|
|
|
|
{
|
|
|
|
|
#define SOPC(op) \
|
|
|
|
|
case aco_opcode::s_cmp_##op##_i32: return true; \
|
|
|
|
|
case aco_opcode::s_cmp_##op##_u32: return false;
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
SOPC(eq)
|
|
|
|
|
SOPC(lg)
|
|
|
|
|
SOPC(gt)
|
|
|
|
|
SOPC(ge)
|
|
|
|
|
SOPC(lt)
|
|
|
|
|
SOPC(le)
|
2025-07-23 09:17:35 +02:00
|
|
|
default: UNREACHABLE("Not a valid SOPC instruction.");
|
2022-04-17 22:14:30 +02:00
|
|
|
}
|
|
|
|
|
#undef SOPC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static aco_opcode
|
2022-07-07 23:54:39 +02:00
|
|
|
sopc_32_swapped(aco_opcode opcode)
|
2022-04-17 22:14:30 +02:00
|
|
|
{
|
|
|
|
|
#define SOPC(op1, op2) \
|
|
|
|
|
case aco_opcode::s_cmp_##op1##_i32: return aco_opcode::s_cmp_##op2##_i32; \
|
|
|
|
|
case aco_opcode::s_cmp_##op1##_u32: return aco_opcode::s_cmp_##op2##_u32;
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
SOPC(eq, eq)
|
|
|
|
|
SOPC(lg, lg)
|
2022-07-07 23:54:39 +02:00
|
|
|
SOPC(gt, lt)
|
|
|
|
|
SOPC(ge, le)
|
|
|
|
|
SOPC(lt, gt)
|
|
|
|
|
SOPC(le, ge)
|
2022-04-17 22:14:30 +02:00
|
|
|
default: return aco_opcode::num_opcodes;
|
|
|
|
|
}
|
|
|
|
|
#undef SOPC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
try_convert_sopc_to_sopk(aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
if (sopk_opcode_for_sopc(instr->opcode) == aco_opcode::num_opcodes)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (instr->operands[0].isLiteral()) {
|
|
|
|
|
std::swap(instr->operands[0], instr->operands[1]);
|
2022-07-07 23:54:39 +02:00
|
|
|
instr->opcode = sopc_32_swapped(instr->opcode);
|
2022-04-17 22:14:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!instr->operands[1].isLiteral())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (instr->operands[0].isFixed() && instr->operands[0].physReg() >= 128)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uint32_t value = instr->operands[1].constantValue();
|
|
|
|
|
|
|
|
|
|
const uint32_t i16_mask = 0xffff8000u;
|
|
|
|
|
|
|
|
|
|
bool value_is_i16 = (value & i16_mask) == 0 || (value & i16_mask) == i16_mask;
|
|
|
|
|
bool value_is_u16 = !(value & 0xffff0000u);
|
|
|
|
|
|
|
|
|
|
if (!value_is_i16 && !value_is_u16)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!value_is_i16 && sopc_is_signed(instr->opcode)) {
|
|
|
|
|
if (instr->opcode == aco_opcode::s_cmp_lg_i32)
|
|
|
|
|
instr->opcode = aco_opcode::s_cmp_lg_u32;
|
|
|
|
|
else if (instr->opcode == aco_opcode::s_cmp_eq_i32)
|
|
|
|
|
instr->opcode = aco_opcode::s_cmp_eq_u32;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
} else if (!value_is_u16 && !sopc_is_signed(instr->opcode)) {
|
|
|
|
|
if (instr->opcode == aco_opcode::s_cmp_lg_u32)
|
|
|
|
|
instr->opcode = aco_opcode::s_cmp_lg_i32;
|
|
|
|
|
else if (instr->opcode == aco_opcode::s_cmp_eq_u32)
|
|
|
|
|
instr->opcode = aco_opcode::s_cmp_eq_i32;
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instr->format = Format::SOPK;
|
2024-03-19 15:46:56 +01:00
|
|
|
SALU_instruction* instr_sopk = &instr->salu();
|
2022-04-17 22:14:30 +02:00
|
|
|
|
|
|
|
|
instr_sopk->imm = instr_sopk->operands[1].constantValue() & 0xffff;
|
|
|
|
|
instr_sopk->opcode = sopk_opcode_for_sopc(instr_sopk->opcode);
|
|
|
|
|
instr_sopk->operands.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 21:54:38 +02:00
|
|
|
static void
|
|
|
|
|
opt_fma_mix_acc(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
/* fma_mix is only dual issued on gfx11 if dst and acc type match */
|
|
|
|
|
bool f2f16 = instr->opcode == aco_opcode::v_fma_mixlo_f16;
|
|
|
|
|
|
|
|
|
|
if (instr->valu().opsel_hi[2] == f2f16 || instr->isDPP())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool is_add = false;
|
|
|
|
|
for (unsigned i = 0; i < 2; i++) {
|
|
|
|
|
uint32_t one = instr->valu().opsel_hi[i] ? 0x3800 : 0x3f800000;
|
|
|
|
|
is_add = instr->operands[i].constantEquals(one) && !instr->valu().neg[i] &&
|
|
|
|
|
!instr->valu().opsel_lo[i];
|
|
|
|
|
if (is_add) {
|
|
|
|
|
instr->valu().swapOperands(0, i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_add && instr->valu().opsel_hi[1] == f2f16) {
|
|
|
|
|
instr->valu().swapOperands(1, 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned literal_count = instr->operands[0].isLiteral() + instr->operands[1].isLiteral() +
|
|
|
|
|
instr->operands[2].isLiteral();
|
|
|
|
|
|
|
|
|
|
if (!f2f16 || literal_count > 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* try to convert constant operand to fp16 */
|
|
|
|
|
for (unsigned i = 2 - is_add; i < 3; i++) {
|
|
|
|
|
if (!instr->operands[i].isConstant())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
float value = uif(instr->operands[i].constantValue());
|
|
|
|
|
uint16_t fp16_val = _mesa_float_to_half(value);
|
|
|
|
|
bool is_denorm = (fp16_val & 0x7fff) != 0 && (fp16_val & 0x7fff) <= 0x3ff;
|
|
|
|
|
|
|
|
|
|
if (_mesa_half_to_float(fp16_val) != value ||
|
|
|
|
|
(is_denorm && !(ctx.fp_mode.denorm16_64 & fp_denorm_keep_in)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
instr->valu().swapOperands(i, 2);
|
|
|
|
|
|
|
|
|
|
Operand op16 = Operand::c16(fp16_val);
|
|
|
|
|
assert(!op16.isLiteral() || instr->operands[2].isLiteral());
|
|
|
|
|
|
|
|
|
|
instr->operands[2] = op16;
|
|
|
|
|
instr->valu().opsel_lo[2] = false;
|
|
|
|
|
instr->valu().opsel_hi[2] = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void
|
|
|
|
|
apply_literals(opt_ctx& ctx, aco_ptr<Instruction>& instr)
|
|
|
|
|
{
|
|
|
|
|
/* Cleanup Dead Instructions */
|
|
|
|
|
if (!instr)
|
|
|
|
|
return;
|
|
|
|
|
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
/* apply literals on SALU/VALU */
|
2019-11-22 15:18:38 +00:00
|
|
|
if (instr->isSALU() || instr->isVALU()) {
|
aco/optimizer: use new helpers to apply literals
Foz-DB Navi21:
Totals from 21009 (26.33% of 79789) affected shaders:
MaxWaves: 495342 -> 495414 (+0.01%)
Instrs: 22345587 -> 22335371 (-0.05%); split: -0.05%, +0.00%
CodeSize: 122095820 -> 121795112 (-0.25%); split: -0.25%, +0.00%
VGPRs: 1025800 -> 1025480 (-0.03%)
Latency: 202876235 -> 203076272 (+0.10%); split: -0.04%, +0.14%
InvThroughput: 47599930 -> 47596113 (-0.01%); split: -0.03%, +0.02%
VClause: 475271 -> 475439 (+0.04%); split: -0.02%, +0.05%
SClause: 700679 -> 700629 (-0.01%); split: -0.01%, +0.01%
Copies: 1628498 -> 1618165 (-0.63%); split: -0.64%, +0.01%
Branches: 567199 -> 567216 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 952134 -> 952043 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 846614 -> 846272 (-0.04%)
VALU: 15572374 -> 15564050 (-0.05%); split: -0.05%, +0.00%
SALU: 2423329 -> 2421319 (-0.08%); split: -0.08%, +0.00%
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Foz-DB Navi31:
Totals from 13049 (16.44% of 79395) affected shaders:
MaxWaves: 357242 -> 357268 (+0.01%)
Instrs: 19955572 -> 19944106 (-0.06%); split: -0.06%, +0.00%
CodeSize: 105689464 -> 105454348 (-0.22%); split: -0.23%, +0.00%
VGPRs: 765744 -> 764952 (-0.10%); split: -0.11%, +0.00%
Latency: 179063640 -> 179141591 (+0.04%); split: -0.02%, +0.07%
InvThroughput: 27978134 -> 27971318 (-0.02%); split: -0.03%, +0.01%
VClause: 386791 -> 386826 (+0.01%); split: -0.02%, +0.03%
SClause: 598113 -> 598106 (-0.00%); split: -0.01%, +0.01%
Copies: 1393111 -> 1383102 (-0.72%); split: -0.73%, +0.01%
Branches: 498533 -> 498535 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 573310 -> 573236 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 591459 -> 591043 (-0.07%)
VALU: 11623734 -> 11615755 (-0.07%); split: -0.07%, +0.00%
SALU: 1962055 -> 1960005 (-0.10%); split: -0.11%, +0.00%
VOPD: 3544 -> 3566 (+0.62%); split: +0.73%, -0.11%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35272>
2024-08-22 22:13:54 +02:00
|
|
|
for (const Operand& op : instr->operands) {
|
|
|
|
|
if (op.isTemp() && ctx.info[op.tempId()].is_literal(op.size() * 32) &&
|
|
|
|
|
ctx.uses[op.tempId()] == 0) {
|
|
|
|
|
alu_opt_info info;
|
|
|
|
|
if (!alu_opt_gather_info(ctx, instr.get(), info))
|
|
|
|
|
UNREACHABLE("We already check that we can apply lit");
|
|
|
|
|
|
|
|
|
|
for (auto& op_info : info.operands) {
|
|
|
|
|
if (op_info.op == op)
|
|
|
|
|
op_info.op = Operand::literal32(ctx.info[op.tempId()].val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!alu_opt_info_is_valid(ctx, info))
|
|
|
|
|
UNREACHABLE("We already check that we can apply lit");
|
|
|
|
|
instr.reset(alu_opt_info_to_instr(ctx, info, instr.release()));
|
|
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 12:05:01 +01:00
|
|
|
if (instr->isSOPC() && ctx.program->gfx_level < GFX12)
|
2022-04-17 22:14:30 +02:00
|
|
|
try_convert_sopc_to_sopk(instr);
|
|
|
|
|
|
2024-05-03 21:54:38 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_fma_mixlo_f16 || instr->opcode == aco_opcode::v_fma_mix_f32)
|
|
|
|
|
opt_fma_mix_acc(ctx, instr);
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.instructions.emplace_back(std::move(instr));
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-30 10:45:13 +02:00
|
|
|
void
|
|
|
|
|
validate_opt_ctx(opt_ctx& ctx)
|
|
|
|
|
{
|
|
|
|
|
if (!(debug_flags & DEBUG_VALIDATE_OPT))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Program* program = ctx.program;
|
|
|
|
|
|
|
|
|
|
bool is_valid = true;
|
|
|
|
|
auto check = [&program, &is_valid](bool success, const char* msg,
|
|
|
|
|
aco::Instruction* instr) -> void
|
|
|
|
|
{
|
|
|
|
|
if (!success) {
|
|
|
|
|
char* out;
|
|
|
|
|
size_t outsize;
|
|
|
|
|
struct u_memstream mem;
|
|
|
|
|
u_memstream_open(&mem, &out, &outsize);
|
|
|
|
|
FILE* const memf = u_memstream_get(&mem);
|
|
|
|
|
|
|
|
|
|
fprintf(memf, "Optimizer: %s: ", msg);
|
|
|
|
|
aco_print_instr(program->gfx_level, instr, memf);
|
|
|
|
|
u_memstream_close(&mem);
|
|
|
|
|
|
|
|
|
|
aco_err(program, "%s", out);
|
|
|
|
|
free(out);
|
|
|
|
|
|
|
|
|
|
is_valid = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (Block& block : program->blocks) {
|
|
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions) {
|
|
|
|
|
if (!instr)
|
|
|
|
|
continue;
|
|
|
|
|
for (const Definition& def : instr->definitions) {
|
|
|
|
|
check(ctx.info[def.tempId()].parent_instr == instr.get(), "parent_instr incorrect",
|
|
|
|
|
instr.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!is_valid) {
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 19:45:23 +02:00
|
|
|
void rename_loop_header_phis(opt_ctx& ctx) {
|
|
|
|
|
for (Block& block : ctx.program->blocks) {
|
|
|
|
|
if (!(block.kind & block_kind_loop_header))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for (auto& instr : block.instructions) {
|
|
|
|
|
if (!is_phi(instr))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++) {
|
|
|
|
|
if (!instr->operands[i].isTemp())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ssa_info info = ctx.info[instr->operands[i].tempId()];
|
|
|
|
|
while (info.is_temp()) {
|
|
|
|
|
pseudo_propagate_temp(ctx, instr, info.temp, i);
|
|
|
|
|
info = ctx.info[info.temp.id()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 16:17:29 +02:00
|
|
|
} /* end namespace */
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
void
|
|
|
|
|
optimize(Program* program)
|
|
|
|
|
{
|
|
|
|
|
opt_ctx ctx;
|
|
|
|
|
ctx.program = program;
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
ctx.info = std::vector<ssa_info>(program->peekAllocationId());
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
/* 1. Bottom-Up DAG pass (forward) to label all ssa-defs */
|
|
|
|
|
for (Block& block : program->blocks) {
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
ctx.fp_mode = block.fp_mode;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions)
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
label_instruction(ctx, instr);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-30 10:45:13 +02:00
|
|
|
validate_opt_ctx(ctx);
|
|
|
|
|
|
2025-04-17 19:45:23 +02:00
|
|
|
rename_loop_header_phis(ctx);
|
|
|
|
|
|
|
|
|
|
validate_opt_ctx(ctx);
|
|
|
|
|
|
2020-05-22 12:52:05 +02:00
|
|
|
ctx.uses = dead_code_analysis(program);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
/* 2. Rematerialize constants in every block. */
|
|
|
|
|
rematerialize_constants(ctx);
|
|
|
|
|
|
2024-07-30 10:45:13 +02:00
|
|
|
validate_opt_ctx(ctx);
|
|
|
|
|
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
/* 3. Combine v_mad, omod, clamp and propagate sgpr on VALU instructions */
|
2019-09-17 13:22:17 +02:00
|
|
|
for (Block& block : program->blocks) {
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
ctx.fp_mode = block.fp_mode;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions)
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
combine_instruction(ctx, instr);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-30 10:45:13 +02:00
|
|
|
validate_opt_ctx(ctx);
|
|
|
|
|
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
/* 4. Top-Down DAG pass (backward) to select instructions (includes DCE) */
|
2020-11-03 14:40:05 +01:00
|
|
|
for (auto block_rit = program->blocks.rbegin(); block_rit != program->blocks.rend();
|
|
|
|
|
++block_rit) {
|
|
|
|
|
Block* block = &(*block_rit);
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
ctx.fp_mode = block->fp_mode;
|
2020-11-03 14:40:05 +01:00
|
|
|
for (auto instr_rit = block->instructions.rbegin(); instr_rit != block->instructions.rend();
|
|
|
|
|
++instr_rit)
|
|
|
|
|
select_instruction(ctx, *instr_rit);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-30 10:45:13 +02:00
|
|
|
validate_opt_ctx(ctx);
|
|
|
|
|
|
aco: rematerialize constants in every basic block during optimizer
Totals from 16837 (21.25% of 79242) affected shaders: (GFX11)
MaxWaves: 441634 -> 444546 (+0.66%); split: +0.66%, -0.00%
Instrs: 25908303 -> 25838469 (-0.27%); split: -0.36%, +0.09%
CodeSize: 133943168 -> 135446948 (+1.12%); split: -0.04%, +1.16%
VGPRs: 985332 -> 977440 (-0.80%); split: -0.83%, +0.03%
SpillSGPRs: 9133 -> 7535 (-17.50%); split: -17.74%, +0.24%
SpillVGPRs: 1418 -> 1359 (-4.16%); split: -4.58%, +0.42%
Scratch: 5047552 -> 5040640 (-0.14%)
Latency: 204330340 -> 204179212 (-0.07%); split: -0.32%, +0.25%
InvThroughput: 36584220 -> 36508856 (-0.21%); split: -0.40%, +0.19%
VClause: 437847 -> 437344 (-0.11%); split: -0.34%, +0.22%
SClause: 771311 -> 771013 (-0.04%); split: -0.42%, +0.38%
Copies: 1774950 -> 1712070 (-3.54%); split: -4.46%, +0.91%
Branches: 580595 -> 580478 (-0.02%); split: -0.03%, +0.01%
PreSGPRs: 877017 -> 817549 (-6.78%)
PreVGPRs: 852747 -> 846966 (-0.68%); split: -0.68%, +0.00%
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26875>
2024-01-04 15:50:10 +01:00
|
|
|
/* 5. Add literals to instructions */
|
2019-09-17 13:22:17 +02:00
|
|
|
for (Block& block : program->blocks) {
|
2022-08-17 00:18:54 +02:00
|
|
|
ctx.instructions.reserve(block.instructions.size());
|
aco: use -1.0*x and 1.0*|x| for fneg/fabs
Besides -1.0*x being 1 dword smaller than x^0x80000000, this commit also
improves generated code when the application requires that denormals are
flushed.
Future versions of DXVK will require that 32-bit denormals are flushed.
fossil-db (GFX8):
Totals from 21021 (14.22% of 147787) affected shaders:
SGPRs: 1288960 -> 1288944 (-0.00%); split: -0.01%, +0.01%
VGPRs: 792672 -> 792848 (+0.02%); split: -0.01%, +0.03%
CodeSize: 62439228 -> 62403552 (-0.06%); split: -0.11%, +0.05%
MaxWaves: 136182 -> 136181 (-0.00%); split: +0.00%, -0.00%
Instrs: 12230882 -> 12239927 (+0.07%); split: -0.01%, +0.08%
fossil-db (GFX10.3):
Totals from 20191 (13.80% of 146267) affected shaders:
VGPRs: 799992 -> 800032 (+0.01%)
CodeSize: 59763656 -> 59715484 (-0.08%); split: -0.12%, +0.03%
MaxWaves: 525378 -> 525376 (-0.00%)
Instrs: 11511082 -> 11517419 (+0.06%); split: -0.00%, +0.06%
fossil-db (GFX8, d3d float controls):
Totals from 87160 (58.98% of 147787) affected shaders:
SGPRs: 5395072 -> 5408480 (+0.25%); split: -0.06%, +0.31%
VGPRs: 3596716 -> 3581592 (-0.42%); split: -0.55%, +0.13%
CodeSize: 271347396 -> 266814460 (-1.67%); split: -1.67%, +0.00%
MaxWaves: 539669 -> 540400 (+0.14%); split: +0.15%, -0.02%
Instrs: 53395194 -> 52257505 (-2.13%); split: -2.13%, +0.00%
fossil-db (GFX10.3, d3d float controls):
Totals from 82306 (56.27% of 146267) affected shaders:
VGPRs: 3572312 -> 3558848 (-0.38%); split: -0.44%, +0.06%
CodeSize: 273494748 -> 269648968 (-1.41%); split: -1.41%, +0.00%
MaxWaves: 2007156 -> 2009950 (+0.14%); split: +0.15%, -0.01%
Instrs: 52251568 -> 51356424 (-1.71%); split: -1.71%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9079>
2020-06-25 11:44:26 +01:00
|
|
|
ctx.fp_mode = block.fp_mode;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions)
|
|
|
|
|
apply_literals(ctx, instr);
|
2022-08-17 00:18:54 +02:00
|
|
|
block.instructions = std::move(ctx.instructions);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2024-07-30 10:45:13 +02:00
|
|
|
|
|
|
|
|
validate_opt_ctx(ctx);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace aco
|