nir/algebraic: make patterns for float conversion lowerings imprecise
authorIsabella Basso <isabellabdoamaral@usp.br>
Fri, 10 Mar 2023 20:20:10 +0000 (17:20 -0300)
committerMarge Bot <emma+marge@anholt.net>
Sat, 11 Mar 2023 17:21:37 +0000 (17:21 +0000)
As noted on [1], lowering patterns of the form
floatS -> floatB -> floatS ==> floatS
cannot require precision since this may cause flush denorming.

[1] 3f779013 ("nir: Add an algebraic optimization for float->double->float")

Fixes: b86305bb ("nir/algebraic: collapse conversion opcodes (many patterns)")
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Signed-off-by: Isabella Basso <isabellabdoamaral@usp.br>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20965>

src/compiler/nir/nir_opt_algebraic.py

index 0c9c5c4..a9493cb 100644 (file)
@@ -994,7 +994,7 @@ for s in [16, 32, 64]:
             optimizations.extend([
                # S = smaller, B = bigger
                # floatS -> floatB -> floatS ==> identity
-               (('f2f{}'.format(s), ('f2f{}'.format(B), 'a@{}'.format(s))), a),
+               (('~f2f{}'.format(s), ('f2f{}'.format(B), 'a@{}'.format(s))), a),
 
                # bool1 -> typeB -> typeS ==> bool1 -> typeS
                (('f2f{}'.format(s), ('b2f{}'.format(B), 'a@1')), ('b2f{}'.format(s), a)),
@@ -1514,10 +1514,6 @@ optimizations.extend([
    (('f2u32', ('f2fmp', 'a@32')), ('f2u32', a)),
    (('i2f32', ('i2imp', 'a@32')), ('i2f32', a)),
 
-   # Conversions from float32 to float64 and back can be removed as long as
-   # it doesn't need to be precise, since the conversion may e.g. flush denorms
-   (('~f2f32', ('f2f64', 'a@32')), a),
-
    (('ffloor', 'a(is_integral)'), a),
    (('fceil', 'a(is_integral)'), a),
    (('ftrunc', 'a(is_integral)'), a),