Mesa (main): spirv: Minor cleanup in SpvOpFOrdNotEqual

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 6 02:17:30 UTC 2021


Module: Mesa
Branch: main
Commit: f8148b861f00cd50a9a408cf5d5ae44b876d17af
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f8148b861f00cd50a9a408cf5d5ae44b876d17af

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Mar 11 16:20:47 2021 -0800

spirv: Minor cleanup in SpvOpFOrdNotEqual

v2: Add a comment explaining why the suboptimal SpvOpFOrdNotEqual
implementation is still used here.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12320>

---

 src/compiler/spirv/vtn_alu.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
index e47b81622cf..6d9794fc954 100644
--- a/src/compiler/spirv/vtn_alu.c
+++ b/src/compiler/spirv/vtn_alu.c
@@ -641,23 +641,20 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
        * from the ALU will probably already be false if the operands are not
        * ordered so we don’t need to handle it specially.
        */
-      bool swap;
-      bool exact;
-      unsigned src_bit_size = glsl_get_bit_size(vtn_src[0]->type);
-      unsigned dst_bit_size = glsl_get_bit_size(dest_type);
-      nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap, &exact,
-                                                  src_bit_size, dst_bit_size);
-
-      assert(!swap);
-      assert(exact);
-
       const bool save_exact = b->nb.exact;
 
       b->nb.exact = true;
 
+      /* This could also be implemented as (a < b || b < a).  If one or both
+       * of the source are numbers, later optimization passes can easily
+       * eliminate the isnan() checks.  This may trim the sequence down to a
+       * single (a != b) operation.  Otherwise, the optimizer can transform
+       * whatever is left to (a < b || b < a).  Since some applications will
+       * open-code this sequence, these optimizations are needed anyway.
+       */
       dest->def =
          nir_iand(&b->nb,
-                  nir_build_alu(&b->nb, op, src[0], src[1], NULL, NULL),
+                  nir_fneu(&b->nb, src[0], src[1]),
                   nir_iand(&b->nb,
                           nir_feq(&b->nb, src[0], src[0]),
                           nir_feq(&b->nb, src[1], src[1])));



More information about the mesa-commit mailing list