diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f4963ef7060..1f2b92fc0d4 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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; diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index bd9b786b91c..db4e6f4d487 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -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'), diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp index dca45e7b73e..f47e0e13c2a 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp @@ -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; diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index c2ea353166b..f320256da29 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -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, diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index e072d62425c..39089d2f245 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -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,