Mesa (master): nir: Add optimization for doing removing f16/f32 conversions

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Feb 24 17:42:03 UTC 2020


Module: Mesa
Branch: master
Commit: 9e8466a866cbfb4c6745d85e9371b43827d16c8d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9e8466a866cbfb4c6745d85e9371b43827d16c8d

Author: Hyunjun Ko <zzoon at igalia.com>
Date:   Mon Aug  5 06:36:38 2019 +0000

nir: Add optimization for doing removing f16/f32 conversions

This eliminates conversions between f16 and f32 where possible. We can
always remove an upcast followed by a down cast, that is:

  f2f16 ( f2f32 (a) )  ->  a
  f2fmp ( f2f32 (a) )  ->  a

In the other direction, f2f16 loses precision and can't be undone by a
f2f32.  However, by definition it's always safe to elminate f2fmp:

  f2f32 ( f2fmp (a) )  ->  a

v2. [Neil Roberts (nroberts at igalia.com)]

Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3822>

---

 src/compiler/nir/nir_opt_algebraic.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 281b3a61e78..5e586a303de 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -831,6 +831,13 @@ optimizations.extend([
    (('~f2u32', ('i2f', 'a at 32')), a),
    (('~f2u32', ('u2f', 'a at 32')), a),
 
+   # Conversions from float16 to float32 and back can always be removed
+   (('f2f16', ('f2f32', 'a at 16')), a),
+   (('f2fmp', ('f2f32', 'a at 16')), a),
+   # Conversions to float16 would be lossy so they should only be removed if
+   # the instruction was generated by the precision lowering pass.
+   (('f2f32', ('f2fmp', 'a at 32')), a),
+
    (('ffloor', 'a(is_integral)'), a),
    (('fceil', 'a(is_integral)'), a),
    (('ftrunc', 'a(is_integral)'), a),



More information about the mesa-commit mailing list