diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index d1e731b0890..12ca5c36f5d 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -78,6 +78,8 @@ static const struct nir_shader_compiler_options nir_options = { .lower_fpow = true, .lower_mul_2x32_64 = true, .lower_rotate = true, + .has_fsub = true, + .has_isub = true, .use_scoped_barrier = true, .max_unroll_iterations = 32, .use_interpolated_input_intrinsics = true, diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index aea91a86a9f..4e924350a1d 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -3252,6 +3252,8 @@ const nir_shader_compiler_options v3d_nir_options = { .lower_wpos_pntc = true, .lower_rotate = true, .lower_to_scalar = true, + .has_fsub = true, + .has_isub = true, }; /** diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 20507e4c219..0274c4a5bb6 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -250,6 +250,8 @@ const nir_shader_compiler_options v3dv_nir_options = { .lower_wpos_pntc = true, .lower_rotate = true, .lower_to_scalar = true, + .has_fsub = true, + .has_isub = true, .vertex_id_zero_based = false, /* FIXME: to set this to true, the intrinsic * needs to be supported */ .lower_interpolate_at = true, diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 1f2b92fc0d4..5d43d6aaf72 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3137,8 +3137,6 @@ typedef struct nir_shader_compiler_options { 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; /* lower {slt,sge,seq,sne} to {flt,fge,feq,fneu} + b2f: */ bool lower_scmp; @@ -3359,6 +3357,14 @@ typedef struct nir_shader_compiler_options { * to imul with masked inputs and iadd */ bool has_umad24; + /** Backend supports fsub, if not set fsub will automatically be lowered to + * fadd(x, fneg(y)). If true, driver should call nir_opt_algebraic_late(). */ + bool has_fsub; + + /** Backend supports isub, if not set isub will automatically be lowered to + * iadd(x, ineg(y)). If true, driver should call nir_opt_algebraic_late(). */ + bool has_isub; + /* Whether to generate only scoped_barrier intrinsics instead of the set of * memory and control barrier intrinsics based on GLSL. */ diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index db4e6f4d487..a1fe299db45 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -2106,9 +2106,9 @@ late_optimizations = [ (('fneg', ('fneg', a)), a), # Subtractions get lowered during optimization, so we need to recombine them - (('fadd', 'a', ('fneg', 'b')), ('fsub', 'a', 'b'), '!options->lower_sub'), + (('fadd', a, ('fneg', 'b')), ('fsub', 'a', 'b'), 'options->has_fsub'), (('fneg', a), ('fmul', a, -1.0), 'options->lower_fneg'), - (('iadd', a, ('ineg', 'b')), ('isub', 'a', 'b'), '!options->lower_sub || options->lower_ineg'), + (('iadd', a, ('ineg', 'b')), ('isub', 'a', 'b'), 'options->has_isub || 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'), diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index d16f036c4ef..9ce26829a25 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -72,6 +72,8 @@ static const nir_shader_compiler_options options = { .lower_rotate = true, .lower_to_scalar = true, .has_imul24 = true, + .has_fsub = true, + .has_isub = true, .lower_wpos_pntc = true, .lower_cs_local_index_from_id = true, @@ -125,6 +127,8 @@ static const nir_shader_compiler_options options_a6xx = { .vectorize_io = true, .lower_to_scalar = true, .has_imul24 = true, + .has_fsub = true, + .has_isub = true, .max_unroll_iterations = 32, .lower_wpos_pntc = true, .lower_cs_local_index_from_id = true, diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index 587c06074be..540e4be236b 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -2703,7 +2703,6 @@ static const nir_shader_compiler_options nir_to_tgsi_compiler_options = { .lower_flrp64 = true, .lower_fmod = true, .lower_rotate = true, - .lower_sub = true, .lower_uniforms_to_ubo = true, .lower_vector_cmp = true, .use_interpolated_input_intrinsics = true, diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c index aa6a7370189..9bcc5d8e944 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_screen.c +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c @@ -1033,7 +1033,6 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu, screen->options = (nir_shader_compiler_options) { .lower_fpow = true, - .lower_sub = true, .lower_ftrunc = true, .fuse_ffma16 = true, .fuse_ffma32 = true, diff --git a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c index be80e4bc504..f5cd12db8bb 100644 --- a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c +++ b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c @@ -45,6 +45,8 @@ static const nir_shader_compiler_options options = { .lower_rotate = true, .lower_vector_cmp = true, .lower_fdph = true, + .has_fsub = true, + .has_isub = true, }; const nir_shader_compiler_options * diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index 5d58750eff1..78b6fadc905 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -50,7 +50,6 @@ static const nir_shader_compiler_options vs_nir_options = { .lower_fdiv = true, .lower_fmod = true, .lower_fsqrt = true, - .lower_sub = true, .lower_flrp32 = true, .lower_flrp64 = true, /* could be implemented by clamp */ @@ -68,7 +67,6 @@ static const nir_shader_compiler_options fs_nir_options = { .lower_fpow = true, .lower_fdiv = true, .lower_fmod = true, - .lower_sub = true, .lower_flrp32 = true, .lower_flrp64 = true, .lower_fsign = true, diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 69b35b8a74d..0ba4b48c469 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -547,7 +547,6 @@ static const struct nir_shader_compiler_options gallivm_nir_options = { .lower_fsat = true, .lower_bitfield_insert_to_shifts = true, .lower_bitfield_extract_to_shifts = true, - .lower_sub = true, .lower_fdot = true, .lower_fdph = true, .lower_ffma16 = true, 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 f47e0e13c2a..417800585da 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp @@ -3234,7 +3234,6 @@ nvir_nir_shader_compiler_options(int chipset) op.lower_mul_high = 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; op.lower_bitops = false; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c b/src/gallium/drivers/nouveau/nv50/nv50_screen.c index 578252a5651..71152a29589 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c @@ -932,7 +932,6 @@ static const nir_shader_compiler_options nir_options = { .lower_fpow = false, .lower_uadd_carry = true, .lower_usub_borrow = true, - .lower_sub = true, .lower_ffract = true, .lower_pack_half_2x16 = true, .lower_pack_unorm_2x16 = true, diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index 7d2909f2de5..2427c035c2b 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -1192,7 +1192,9 @@ const struct nir_shader_compiler_options r600_nir_fs_options = { .vectorize_io = true, .has_umad24 = true, .has_umul24 = true, - .use_interpolated_input_intrinsics = true + .use_interpolated_input_intrinsics = true, + .has_fsub = true, + .has_isub = true, }; const struct nir_shader_compiler_options r600_nir_options = { @@ -1214,6 +1216,8 @@ const struct nir_shader_compiler_options r600_nir_options = { .vectorize_io = true, .has_umad24 = true, .has_umul24 = true, + .has_fsub = true, + .has_isub = true, }; diff --git a/src/gallium/drivers/radeonsi/si_get.c b/src/gallium/drivers/radeonsi/si_get.c index 992552bf66b..a12c42a875e 100644 --- a/src/gallium/drivers/radeonsi/si_get.c +++ b/src/gallium/drivers/radeonsi/si_get.c @@ -926,7 +926,6 @@ void si_init_screen_get_functions(struct si_screen *sscreen) .lower_fdiv = true, .lower_bitfield_insert_to_bitfield_select = true, .lower_bitfield_extract = true, - .lower_sub = true, /* |---------------------------------- Performance & Availability --------------------------------| * |MAD/MAC/MADAK/MADMK|MAD_LEGACY|MAC_LEGACY| FMA |FMAC/FMAAK/FMAMK|FMA_LEGACY|PK_FMA_F16,|Best choice * Arch | F32,F16,F64 | F32,F16 | F32,F16 |F32,F16,F64 | F32,F16 | F32,F16 |PK_FMAC_F16|F16,F32,F64 diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index ed826e4fc60..3d5ea4dce95 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -82,7 +82,6 @@ static const nir_shader_compiler_options sp_compiler_options = { .lower_flrp64 = true, .lower_fmod = true, .lower_rotate = true, - .lower_sub = true, .lower_uniforms_to_ubo = true, .lower_vector_cmp = true, .use_interpolated_input_intrinsics = true, diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index f320256da29..58cbf4dd7a7 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -2190,6 +2190,8 @@ static const nir_shader_compiler_options nir_options = { .lower_umax = true, .lower_umin = true, .lower_isign = true, + .has_fsub = true, + .has_isub = true, .max_unroll_iterations = 32, }; diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 87f62fa1de2..832ba9a210e 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -224,6 +224,8 @@ zink_screen_init_compiler(struct zink_screen *screen) .use_scoped_barrier = true, .lower_int64_options = 0, .lower_doubles_options = ~nir_lower_fp64_full_software, + .has_fsub = true, + .has_isub = true, }; screen->nir_options = default_options; diff --git a/src/intel/compiler/brw_compiler.c b/src/intel/compiler/brw_compiler.c index 943b621daa9..032e615602e 100644 --- a/src/intel/compiler/brw_compiler.c +++ b/src/intel/compiler/brw_compiler.c @@ -30,7 +30,6 @@ #include "util/debug.h" #define COMMON_OPTIONS \ - .lower_sub = true, \ .lower_fdiv = true, \ .lower_scmp = true, \ .lower_flrp16 = true, \ diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 39089d2f245..6156848c161 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -98,6 +98,8 @@ nir_options = { .lower_pack_32_2x16_split = true, .lower_unpack_64_2x32_split = true, .lower_unpack_32_2x16_split = true, + .has_fsub = true, + .has_isub = true, .use_scoped_barrier = true, .vertex_id_zero_based = true, .lower_base_vertex = true, diff --git a/src/panfrost/bifrost/bifrost_compile.h b/src/panfrost/bifrost/bifrost_compile.h index 2ea6528c08c..2c6d6217d93 100644 --- a/src/panfrost/bifrost/bifrost_compile.h +++ b/src/panfrost/bifrost/bifrost_compile.h @@ -69,6 +69,8 @@ static const nir_shader_compiler_options bifrost_nir_options = { .lower_doubles_options = nir_lower_dmod, .lower_bitfield_extract_to_shifts = true, + .has_fsub = true, + .has_isub = true, .vectorize_io = true, .fuse_ffma16 = true, .fuse_ffma32 = true, diff --git a/src/panfrost/midgard/midgard_compile.h b/src/panfrost/midgard/midgard_compile.h index 3b393998393..71314f66c0b 100644 --- a/src/panfrost/midgard/midgard_compile.h +++ b/src/panfrost/midgard/midgard_compile.h @@ -78,6 +78,8 @@ static const nir_shader_compiler_options midgard_nir_options = { .lower_doubles_options = nir_lower_dmod, .lower_bitfield_extract_to_shifts = true, + .has_fsub = true, + .has_isub = true, .vectorize_io = true, .use_interpolated_input_intrinsics = true,