nir,vc4: Lower fneg to fmul(x, -1.0)

This patch also replaces lower_negate with lower_ineg / lower_fneg.

The fneg semantics have been clarified as of Version 1.5, Revision 1
of the SPIR-V specification, which means that the previous lowering
to fsub is not a viable solution anymore, and is replaced with
lowering to fmul(x, -1.0).

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6597>
This commit is contained in:
Daniel Schürmann 2020-08-27 14:35:04 +01:00 committed by Marge Bot
parent 556a5cb575
commit b3ce55b445
5 changed files with 13 additions and 8 deletions

View File

@ -3133,8 +3133,10 @@ typedef struct nir_shader_compiler_options {
bool lower_usub_borrow;
/** Lowers imul_high/umul_high to 16-bit multiplies and carry operations. */
bool lower_mul_high;
/** lowers fneg and ineg to fsub and isub. */
bool lower_negate;
/** lowers fneg to fmul(x, -1.0). Driver must call nir_opt_algebraic_late() */
bool lower_fneg;
/** lowers ineg to isub. Driver must call nir_opt_algebraic_late(). */
bool lower_ineg;
/** lowers fsub and isub to fadd+fneg and iadd+ineg. */
bool lower_sub;

View File

@ -2107,9 +2107,9 @@ late_optimizations = [
# Subtractions get lowered during optimization, so we need to recombine them
(('fadd', 'a', ('fneg', 'b')), ('fsub', 'a', 'b'), '!options->lower_sub'),
(('iadd', 'a', ('ineg', 'b')), ('isub', 'a', 'b'), '!options->lower_sub'),
(('fneg', a), ('fsub', 0.0, a), 'options->lower_negate'),
(('ineg', a), ('isub', 0, a), 'options->lower_negate'),
(('fneg', a), ('fmul', a, -1.0), 'options->lower_fneg'),
(('iadd', a, ('ineg', 'b')), ('isub', 'a', 'b'), '!options->lower_sub || options->lower_ineg'),
(('ineg', a), ('isub', 0, a), 'options->lower_ineg'),
(('iabs', a), ('imax', a, ('ineg', a)), 'options->lower_iabs'),
(('~fadd@16', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma16'),
(('~fadd@32', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma32'),

View File

@ -3232,7 +3232,8 @@ nvir_nir_shader_compiler_options(int chipset)
op.lower_uadd_carry = true; // TODO
op.lower_usub_borrow = true; // TODO
op.lower_mul_high = false;
op.lower_negate = false;
op.lower_fneg = false;
op.lower_ineg = false;
op.lower_sub = true;
op.lower_scmp = true; // TODO: not implemented yet
op.lower_vector_cmp = false;

View File

@ -2183,7 +2183,8 @@ static const nir_shader_compiler_options nir_options = {
.lower_fsat = true,
.lower_fsqrt = true,
.lower_ldexp = true,
.lower_negate = true,
.lower_fneg = true,
.lower_ineg = true,
.lower_rotate = true,
.lower_to_scalar = true,
.lower_umax = true,

View File

@ -70,7 +70,8 @@ DEBUG_GET_ONCE_FLAGS_OPTION(debug_dxil, "DXIL_DEBUG", dxil_debug_options, 0)
static const nir_shader_compiler_options
nir_options = {
.lower_negate = true,
.lower_ineg = true,
.lower_fneg = true,
.lower_ffma16 = true,
.lower_ffma32 = true,
.lower_isign = true,