nak: Move imad late optimization to nir
It is more or less just a code move, but I touched is_only_used_by_iadd(..) to match the style of the other functions in that file. Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30099>
This commit is contained in:
committed by
Marge Bot
parent
e019517d6e
commit
87786a7a7e
@@ -3143,7 +3143,10 @@ late_optimizations = [
|
||||
|
||||
# nir_lower_to_source_mods will collapse this, but its existence during the
|
||||
# optimization loop can prevent other optimizations.
|
||||
(('fneg', ('fneg', a)), a)
|
||||
(('fneg', ('fneg', a)), a),
|
||||
|
||||
# combine imul and iadd to imad
|
||||
(('iadd@32', ('imul(is_only_used_by_iadd)', a, b), c), ('imad', a, b, c), 'options->has_imad32'),
|
||||
]
|
||||
|
||||
# re-combine inexact mul+add to ffma. Do this before fsub so that a * b - c
|
||||
|
||||
@@ -583,6 +583,24 @@ is_only_used_by_fadd(const nir_alu_instr *instr)
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
is_only_used_by_iadd(const nir_alu_instr *instr)
|
||||
{
|
||||
nir_foreach_use(src, &instr->def) {
|
||||
const nir_instr *const user_instr = nir_src_parent_instr(src);
|
||||
if (user_instr->type != nir_instr_type_alu)
|
||||
return false;
|
||||
|
||||
const nir_alu_instr *const user_alu = nir_instr_as_alu(user_instr);
|
||||
assert(instr != user_alu);
|
||||
|
||||
if (user_alu->op != nir_op_iadd)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
only_lower_8_bits_used(const nir_alu_instr *instr)
|
||||
{
|
||||
|
||||
@@ -39,11 +39,6 @@ algebraic_lowering = [
|
||||
(('umax', 'a', 'b'), ('bcsel', ('ult', a, b), b, a), volta),
|
||||
]
|
||||
|
||||
late_optimizations = [
|
||||
(('iadd@32', ('imul(nak_is_only_used_by_iadd)', a, b), c),
|
||||
('imad', a, b, c), 'nak->sm >= 70'),
|
||||
]
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--out', required=True, help='Output file.')
|
||||
@@ -58,7 +53,7 @@ def main():
|
||||
f.write('#include "nak_private.h"')
|
||||
f.write(nir_algebraic.AlgebraicPass(
|
||||
"nak_nir_lower_algebraic_late",
|
||||
algebraic_lowering + late_optimizations,
|
||||
algebraic_lowering,
|
||||
[
|
||||
("const struct nak_compiler *", "nak"),
|
||||
]).render())
|
||||
|
||||
@@ -222,21 +222,6 @@ bool nak_nir_lower_non_uniform_ldcx(nir_shader *nir);
|
||||
bool nak_nir_add_barriers(nir_shader *nir, const struct nak_compiler *nak);
|
||||
bool nak_nir_lower_cf(nir_shader *nir);
|
||||
|
||||
static inline bool
|
||||
nak_is_only_used_by_iadd(const nir_alu_instr *instr)
|
||||
{
|
||||
nir_foreach_use(src, &instr->def) {
|
||||
nir_instr *use = nir_src_parent_instr(src);
|
||||
if (use->type != nir_instr_type_alu)
|
||||
return false;
|
||||
|
||||
if (nir_instr_as_alu(use)->op != nir_op_iadd)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void nak_optimize_nir(nir_shader *nir, const struct nak_compiler *nak);
|
||||
|
||||
struct nak_memstream {
|
||||
|
||||
Reference in New Issue
Block a user