From b729cd58d76f97f3fc04a67569535ee5ef2f5278 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 15 Jul 2020 11:19:56 +0100 Subject: [PATCH] nir/algebraic: eliminate exact a*0.0 if float execution mode allow it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fossil-db (GFX10): Totals from 611 (0.44% of 139391) affected shaders: SGPRs: 40528 -> 40288 (-0.59%) VGPRs: 16136 -> 16152 (+0.10%); split: -0.15%, +0.25% CodeSize: 970192 -> 951036 (-1.97%) MaxWaves: 10561 -> 10557 (-0.04%); split: +0.08%, -0.11% Instrs: 174874 -> 172879 (-1.14%); split: -1.18%, +0.04% fossil-db (GFX10.3): Totals from 611 (0.44% of 139391) affected shaders: SGPRs: 40680 -> 40488 (-0.47%) VGPRs: 18368 -> 18276 (-0.50%); split: -0.57%, +0.07% CodeSize: 1050712 -> 1033624 (-1.63%); split: -1.64%, +0.02% MaxWaves: 8658 -> 8674 (+0.18%) Instrs: 205364 -> 201220 (-2.02%) Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 73c0b3767cf..ed7826da63b 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -147,6 +147,9 @@ optimizations = [ (('~fadd', a, ('fadd', ('fneg', a), b)), b), (('fadd', ('fsat', a), ('fsat', ('fneg', a))), ('fsat', ('fabs', a))), (('~fmul', a, 0.0), 0.0), + # The only effect a*0.0 should have is when 'a' is infinity, -0.0 or NaN + (('fmul', 'a@16', 0.0), 0.0, '!'+signed_zero_inf_nan_preserve_16), + (('fmul', 'a@32', 0.0), 0.0, '!'+signed_zero_inf_nan_preserve_32), (('imul', a, 0), 0), (('umul_unorm_4x8', a, 0), 0), (('umul_unorm_4x8', a, ~0), a), @@ -165,6 +168,8 @@ optimizations = [ (('fmul', ('fsign', a), ('fmul', a, a)), ('fmul', ('fabs', a), a)), (('fmul', ('fmul', ('fsign', a), a), a), ('fmul', ('fabs', a), a)), (('~ffma', 0.0, a, b), b), + (('ffma@16(is_only_used_as_float)', 0.0, a, b), b, '!'+signed_zero_inf_nan_preserve_16), + (('ffma@32(is_only_used_as_float)', 0.0, a, b), b, '!'+signed_zero_inf_nan_preserve_32), (('~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),