nir/opt_algebraic: optimize f2i32(fround_even(x)) to f2i32_rtne(x)

Add late optimization to fuse f2i32 and fround_even operations into a
single f2i32_rtne instruction when the intermediate fround_even result
is only used once. This eliminates redundant rounding since f2i32_rtne
performs round-to-nearest-even conversion directly.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Tested-by: Simon Perretta <simon.perretta@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37426>
This commit is contained in:
Christian Gmeiner 2025-09-16 23:42:50 +02:00 committed by Marge Bot
parent 0f320b7a1d
commit a7d2570296
2 changed files with 7 additions and 0 deletions

View file

@ -4024,6 +4024,10 @@ for s in [16, 32, 64]:
(('bcsel@{}'.format(s), ('ine', 0, 'a@{}'.format(s)), 'b@{}'.format(s), 'c@{}'.format(s)), ('icsel_eqz', a, c, b), "options->has_icsel_eqz{} && !options->no_integers".format(s)),
])
late_optimizations += [
(('f2i32', ('fround_even(is_used_once)', 'a@32')), ('f2i32_rtne', a), 'options->has_f2i32_rtne'),
]
distribute_src_mods = [
# Try to remove some spurious negations rather than pushing them down.
(('fmul', ('fneg', a), ('fneg', b)), ('fmul', a, b)),

View file

@ -646,6 +646,9 @@ typedef struct nir_shader_compiler_options {
/** Backend supports load_global_bounded intrinsics. */
bool has_load_global_bounded;
/** Backend supports f2i32_rtne opcode. */
bool has_f2i32_rtne;
/**
* Is this the Intel vec4 backend?
*