<div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 10, 2019 at 12:59 PM Alyssa Rosenzweig <<a href="mailto:alyssa@rosenzweig.io">alyssa@rosenzweig.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This allows algebraic optimizations to check if the argument accesses<br>
multiple distinct components of a vector. So a swizzle like "xyz" will<br>
return true, but "yyy" will return false, as will a scalar. This can be<br>
useful for optimizations on vector processors, where a scalar<br>
swizzle can be handled in one clock (replicated a scalar channel) but a<br>
non-scalar swizzle requires multiple scalarized operations. In these<br>
cases, it is useful to optimize differently based on whether the swizzle<br>
is non-scalar.<br>
<br>
For my use case, csel on Midgard requires a scalar condition, so this<br>
allows csel to be lowered only with a vector condition.<br>
<br>
Signed-off-by: Alyssa Rosenzweig <<a href="mailto:alyssa@rosenzweig.io" target="_blank">alyssa@rosenzweig.io</a>><br>
Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>><br>
Cc: Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" target="_blank">imirkin@alum.mit.edu</a>><br>
---<br>
 src/compiler/nir/nir_search_helpers.h | 17 +++++++++++++++++<br>
 1 file changed, 17 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h<br>
index 1624508993d..8e26739a3ce 100644<br>
--- a/src/compiler/nir/nir_search_helpers.h<br>
+++ b/src/compiler/nir/nir_search_helpers.h<br>
@@ -143,6 +143,23 @@ is_not_const(nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components,<br>
    return !nir_src_is_const(instr->src[src].src);<br>
 }<br>
<br>
+/* I.e. the vector's swizzle actually accesses multiple channels. True for<br>
+ * xyzw, false for wwww, false for w */<br>
+<br>
+static inline bool<br>
+is_non_scalar_swizzle(nir_alu_instr *instr, UNUSED unsigned src, <br>
+             unsigned num_components, const uint8_t *swizzle)<br>
+{<br>
+   unsigned first_component = swizzle[0];<br>
+<br>
+   for (unsigned i = 1; i < num_components; ++i) {<br>
+      if (swizzle[i] != first_component)<br>
+         return true;<br>
+   }<br>
+<br>
+   return false;<br>
+}<br>
+<br>
 static inline bool<br>
 is_used_more_than_once(nir_alu_instr *instr)<br>
 {<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div>