From 79c94ef52ef23a10bea02525ef4bcf60675f2b4f Mon Sep 17 00:00:00 2001 From: Isabella Basso Date: Fri, 10 Mar 2023 17:20:09 -0300 Subject: [PATCH] nir/algebraic: extend lowering patterns for conversions on smaller bit sizes Conversions on smaller bit sizes should also be collapsed when composed. This also adds more patterns on the intS -> intB -> floatB ==> intS -> floatB lowering so as to deal with any int size C > B instead of a fixed intB. Closes: #7776 Acked-by: Alyssa Rosenzweig Reviewed-by: Georg Lehmann Signed-off-by: Isabella Basso Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 4857f62..0c9c5c4 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -993,10 +993,8 @@ for s in [16, 32, 64]: if s < B: optimizations.extend([ # S = smaller, B = bigger - # typeS -> typeB -> typeS ==> identity + # floatS -> floatB -> floatS ==> identity (('f2f{}'.format(s), ('f2f{}'.format(B), 'a@{}'.format(s))), a), - (('i2i{}'.format(s), ('i2i{}'.format(B), 'a@{}'.format(s))), a), - (('u2u{}'.format(s), ('u2u{}'.format(B), 'a@{}'.format(s))), a), # bool1 -> typeB -> typeS ==> bool1 -> typeS (('f2f{}'.format(s), ('b2f{}'.format(B), 'a@1')), ('b2f{}'.format(s), a)), @@ -1010,10 +1008,27 @@ for s in [16, 32, 64]: # int? -> floatB -> floatS ==> int? -> floatS (('f2f{}'.format(s), ('u2f{}'.format(B), a)), ('u2f{}'.format(s), a)), (('f2f{}'.format(s), ('i2f{}'.format(B), a)), ('i2f{}'.format(s), a)), + ]) + +for S in [1, 8, 16, 32]: + for B in [8, 16, 32, 64]: + if B <= S: + continue + optimizations.extend([ + # intS -> intB -> intS ==> identity + (('i2i{}'.format(S), ('i2i{}'.format(B), 'a@{}'.format(S))), a), + (('u2u{}'.format(S), ('u2u{}'.format(B), 'a@{}'.format(S))), a), + ]) - # intS -> intB -> floatB ==> intS -> floatB - (('u2f{}'.format(B), ('u2u{}'.format(B), 'a@{}'.format(s))), ('u2f{}'.format(B), a)), - (('i2f{}'.format(B), ('i2i{}'.format(B), 'a@{}'.format(s))), ('i2f{}'.format(B), a)), + if B < 16: + continue + for C in [8, 16, 32, 64]: + if C <= S: + continue + optimizations.extend([ + # intS -> intC -> floatB ==> intS -> floatB + (('u2f{}'.format(B), ('u2u{}'.format(C), 'a@{}'.format(S))), ('u2f{}'.format(B), a)), + (('i2f{}'.format(B), ('i2i{}'.format(C), 'a@{}'.format(S))), ('i2f{}'.format(B), a)), ]) # mediump variants of the above -- 2.7.4