From 80117117bda10144df57614e718b8c19ee7afdf4 Mon Sep 17 00:00:00 2001 From: Sagar Ghuge Date: Thu, 30 May 2019 14:15:51 -0700 Subject: [PATCH] nir: Add optimization to use ROR/ROL instructions v2: 1) Add more optimization rules for ROL/ROR (Matt Turner) 2) Add lowering rules for ROL/ROR (Matt Turner) Signed-off-by: Sagar Ghuge Reviewed-by: Matt Turner --- src/compiler/nir/nir.h | 3 +++ src/compiler/nir/nir_opt_algebraic.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index df6dc5b..56b5c99 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2423,6 +2423,9 @@ typedef struct nir_shader_compiler_options { /* Lowers when 32x32->64 bit multiplication is not supported */ bool lower_mul_2x32_64; + /* Lowers when rotate instruction is not supported */ + bool lower_rotate; + unsigned max_unroll_iterations; nir_lower_int64_options lower_int64_options; diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index a8f0a83..771a824 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -585,6 +585,18 @@ optimizations = [ (('ushr', a, 0), a), (('iand', 0xff, ('ushr@32', a, 24)), ('ushr', a, 24)), (('iand', 0xffff, ('ushr@32', a, 16)), ('ushr', a, 16)), + (('ior', ('ishl@16', a, b), ('ushr@16', a, ('iadd', 16, ('ineg', b)))), ('urol', a, b), '!options->lower_rotate'), + (('ior', ('ishl@16', a, b), ('ushr@16', a, ('isub', 16, b))), ('urol', a, b), '!options->lower_rotate'), + (('ior', ('ishl@32', a, b), ('ushr@32', a, ('iadd', 32, ('ineg', b)))), ('urol', a, b), '!options->lower_rotate'), + (('ior', ('ishl@32', a, b), ('ushr@32', a, ('isub', 32, b))), ('urol', a, b), '!options->lower_rotate'), + (('ior', ('ushr@16', a, b), ('ishl@16', a, ('iadd', 16, ('ineg', b)))), ('uror', a, b), '!options->lower_rotate'), + (('ior', ('ushr@16', a, b), ('ishl@16', a, ('isub', 16, b))), ('uror', a, b), '!options->lower_rotate'), + (('ior', ('ushr@32', a, b), ('ishl@32', a, ('iadd', 32, ('ineg', b)))), ('uror', a, b), '!options->lower_rotate'), + (('ior', ('ushr@32', a, b), ('ishl@32', a, ('isub', 32, b))), ('uror', a, b), '!options->lower_rotate'), + (('urol@16', a, b), ('ior', ('ishl', a, b), ('ushr', a, ('isub', 16, b))), 'options->lower_rotate'), + (('urol@32', a, b), ('ior', ('ishl', a, b), ('ushr', a, ('isub', 32, b))), 'options->lower_rotate'), + (('uror@16', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 16, b))), 'options->lower_rotate'), + (('uror@32', a, b), ('ior', ('ushr', a, b), ('ishl', a, ('isub', 32, b))), 'options->lower_rotate'), # Exponential/logarithmic identities (('~fexp2', ('flog2', a)), a), # 2^lg2(a) = a (('~flog2', ('fexp2', a)), a), # lg2(2^a) = a -- 2.7.4