Mesa (master): nir/algebraic: Don't put quotes around floating point literals

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 19 07:29:15 UTC 2018


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Dec 18 13:28:22 2018 -0800

nir/algebraic: Don't put quotes around floating point literals

The quotation marks around 1.0 cause it to be treated as a string
instead of a floating point value.  The generator then treats it as an
arbitrary variable replacement, so any iand involving a ('ineg', ('b2i',
a)) matches.

v2: Remove misleading comment about sized literals (suggested by
Timothy).  Add assertion that the name of a varible is entierly
alphabetic (suggested by Jason).

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Tested-by: Timothy Arceri <tarceri at itsqueeze.com> [v1]
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com> [v1]
Fixes: 6bcd2af0863 ("nir/algebraic: Add some optimizations for D3D-style Booleans")
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109075

---

 src/compiler/nir/nir_algebraic.py     |  8 ++++++++
 src/compiler/nir/nir_opt_algebraic.py | 10 +++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index a667c4170f..238127235f 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -252,6 +252,14 @@ class Variable(Value):
       assert m and m.group('name') is not None
 
       self.var_name = m.group('name')
+
+      # Prevent common cases where someone puts quotes around a literal
+      # constant.  If we want to support names that have numeric or
+      # punctuation characters, we can me the first assertion more flexible.
+      assert self.var_name.isalpha()
+      assert self.var_name is not 'True'
+      assert self.var_name is not 'False'
+
       self.is_constant = m.group('const') is not None
       self.cond = m.group('cond')
       self.required_type = m.group('type')
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 506d45e55b..75a3d2ad23 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -61,10 +61,10 @@ d = 'd'
 #
 # All expression types can have a bit-size specified.  For opcodes, this
 # looks like "op at 32", for variables it is "a at 32" or "a at uint32" to specify a
-# type and size, and for literals, you can write "2.0 at 32".  In the search half
-# of the expression this indicates that it should only match that particular
-# bit-size.  In the replace half of the expression this indicates that the
-# constructed value should have that bit-size.
+# type and size.  In the search half of the expression this indicates that it
+# should only match that particular bit-size.  In the replace half of the
+# expression this indicates that the constructed value should have that
+# bit-size.
 
 optimizations = [
 
@@ -545,7 +545,7 @@ optimizations = [
    (('ieq', ('ineg', ('b2i', 'a at 1')), -1), a),
    (('ine', ('ineg', ('b2i', 'a at 1')), 0), a),
    (('ine', ('ineg', ('b2i', 'a at 1')), -1), ('inot', a)),
-   (('iand', ('ineg', ('b2i', a)), '1.0 at 32'), ('b2f', a)),
+   (('iand', ('ineg', ('b2i', a)), 1.0), ('b2f', a)),
 
    # Conversions
    (('i2b32', ('b2i', 'a at 32')), a),




More information about the mesa-commit mailing list