[Mesa-dev] [PATCH v2 1/2] nir: Add is_divergent_vector search helper

Alyssa Rosenzweig alyssa at rosenzweig.io
Fri May 10 16:08:02 UTC 2019


This allows algebraic optimizations to check if the argument accesses
multiple distinct components of a vector. So a swizzle like "xyz" will
return true, but "yyy" will return false, as will a scalar. This can be
useful for optimizations on vector processors, where a convergent
swizzle can be done in one clock (replicating as if a scalar) but a
divergent one must be scalarized. In these cases, it is useful to
optimize differently based on whether the swizzle diverges. (Use case is
the "csel" condition on Midgard).

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
Cc: Jason Ekstrand <jason at jlekstrand.net>
Cc: Ilia Mirkin <imirkin at alum.mit.edu>
---
 src/compiler/nir/nir_search_helpers.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h
index 1624508993d..8e26739a3ce 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -143,6 +143,23 @@ is_not_const(nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components,
    return !nir_src_is_const(instr->src[src].src);
 }
 
+/* I.e. the vector's swizzle actually accesses multiple channels. True for
+ * xyzw, false for wwww, false for w */
+
+static inline bool
+is_non_scalar_swizzle(nir_alu_instr *instr, UNUSED unsigned src, 
+             unsigned num_components, const uint8_t *swizzle)
+{
+   unsigned first_component = swizzle[0];
+
+   for (unsigned i = 1; i < num_components; ++i) {
+      if (swizzle[i] != first_component)
+         return true;
+   }
+
+   return false;
+}
+
 static inline bool
 is_used_more_than_once(nir_alu_instr *instr)
 {
-- 
2.20.1



More information about the mesa-dev mailing list