nir+r600: add option to avoid contracting fabs into ffma
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

On r600 ternary operations can't use the fabs source modifier, so
converting "fadd(fabs(fmul(a, b), c)" to  "ffma(fabs(a), fabs(b), c)"
adds one more instruction in the backend, hence avoid this.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37440>
This commit is contained in:
Gert Wollny 2025-09-17 15:29:49 +02:00 committed by Marge Bot
parent a7d2570296
commit 3b3c3ccf56
3 changed files with 9 additions and 2 deletions

View file

@ -3650,6 +3650,7 @@ for sz, mulz in itertools.product([16, 32, 64], [False, True]):
fadd = 'fadd@{}(contract)'.format(sz)
option = 'options->fuse_ffma{}'.format(sz)
option_with_abs = 'options->fuse_ffma{} && !options->avoid_ternary_with_fabs'.format(sz)
late_optimizations.extend([
((fadd, (fmul, a, b), c), (ffma, a, b, c), option),
@ -3658,10 +3659,10 @@ for sz, mulz in itertools.product([16, 32, 64], [False, True]):
(ffma, ('fneg', a), b, c), option),
((fadd, ('fabs(is_only_used_by_fadd)', (fmul, a, b)), c),
(ffma, ('fabs', a), ('fabs', b), c), option),
(ffma, ('fabs', a), ('fabs', b), c), option_with_abs),
((fadd, ('fneg(is_only_used_by_fadd)', ('fabs', (fmul, a, b))), c),
(ffma, ('fneg', ('fabs', a)), ('fabs', b), c), option),
(ffma, ('fneg', ('fabs', a)), ('fabs', b), c), option_with_abs),
])
late_optimizations.extend([

View file

@ -665,6 +665,11 @@ typedef struct nir_shader_compiler_options {
*/
bool avoid_ternary_with_two_constants;
/* Avoid using fabs on sources to ternary operations
* r600 can't use source modifiers for these
*/
bool avoid_ternary_with_fabs;
/** Whether 8-bit ALU is supported. */
bool support_8bit_alu;

View file

@ -1166,6 +1166,7 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
.vectorize_tess_levels = 1,
.io_options = nir_io_mediump_is_32bit,
.vertex_id_zero_based = rscreen->info.gfx_level >= EVERGREEN,
.avoid_ternary_with_fabs = 1,
};
rscreen->nir_options = nir_options;