From 614ab26afd05dbb9a99ef6a3cde75ba55279ed32 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 15 Jul 2020 11:16:33 +0100 Subject: [PATCH] nir/algebraic: optimize out exact a+0.0 if it's used only as a float MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fossil-db (GFX10): Totals from 133 (0.10% of 139391) affected shaders: SGPRs: 7864 -> 7856 (-0.10%); split: -0.20%, +0.10% VGPRs: 4884 -> 4836 (-0.98%) CodeSize: 288932 -> 287084 (-0.64%) MaxWaves: 1973 -> 1979 (+0.30%) Instrs: 53899 -> 53550 (-0.65%) fossil-db (GFX10.3): Totals from 133 (0.10% of 139391) affected shaders: SGPRs: 7832 -> 7835 (+0.04%); split: -0.06%, +0.10% VGPRs: 5144 -> 5088 (-1.09%) CodeSize: 318912 -> 316696 (-0.69%) MaxWaves: 1735 -> 1746 (+0.63%) Instrs: 65367 -> 64853 (-0.79%) Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index a506160c537..73c0b3767cf 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -40,6 +40,9 @@ c = 'c' d = 'd' e = 'e' +signed_zero_inf_nan_preserve_16 = 'nir_is_float_control_signed_zero_inf_nan_preserve(info->float_controls_execution_mode, 16)' +signed_zero_inf_nan_preserve_32 = 'nir_is_float_control_signed_zero_inf_nan_preserve(info->float_controls_execution_mode, 32)' + # Written in the form (, ) where is an expression # and is either an expression or a value. An expression is # defined as a tuple of the form ([~], , , , ) @@ -124,6 +127,11 @@ optimizations = [ (('f2b', ('fneg', a)), ('f2b', a)), (('i2b', ('ineg', a)), ('i2b', a)), (('~fadd', a, 0.0), a), + # a+0.0 is 'a' unless 'a' is denormal or -0.0. If it's only used by a + # floating point instruction, they should flush any input denormals and we + # can replace -0.0 with 0.0 if the float execution mode allows it. + (('fadd(is_only_used_as_float)', 'a@16', 0.0), a, '!'+signed_zero_inf_nan_preserve_16), + (('fadd(is_only_used_as_float)', 'a@32', 0.0), a, '!'+signed_zero_inf_nan_preserve_32), (('iadd', a, 0), a), (('usadd_4x8', a, 0), a), (('usadd_4x8', a, ~0), ~0), @@ -158,6 +166,8 @@ optimizations = [ (('fmul', ('fmul', ('fsign', a), a), a), ('fmul', ('fabs', a), a)), (('~ffma', 0.0, a, b), b), (('~ffma', a, b, 0.0), ('fmul', a, b)), + (('ffma@16', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_inf_nan_preserve_16), + (('ffma@32', a, b, 0.0), ('fmul', a, b), '!'+signed_zero_inf_nan_preserve_32), (('ffma', 1.0, a, b), ('fadd', a, b)), (('ffma', -1.0, a, b), ('fadd', ('fneg', a), b)), (('~flrp', a, b, 0.0), a),