nir/source_mods: Add a helpers for setting source modifiers
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 6 May 2019 20:30:36 +0000 (15:30 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Fri, 24 May 2019 13:38:11 +0000 (08:38 -0500)
It's potentially a tiny bit less efficient but the helpers make it much
easier to sort out the rules for updating source modifiers.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/compiler/nir/nir_lower_to_source_mods.c

index 3ca53c3..3315a18 100644 (file)
  * easier to not have them when we're doing optimizations.
  */
 
+static void
+alu_src_consume_abs(nir_alu_src *src)
+{
+   src->abs = true;
+}
+
+static void
+alu_src_consume_negate(nir_alu_src *src)
+{
+   /* If abs is set on the source, the negate goes away */
+   if (!src->abs)
+      src->negate = !src->negate;
+}
+
 static bool
 nir_lower_to_source_mods_block(nir_block *block,
                                nir_lower_to_source_mods_flags options)
@@ -88,12 +102,10 @@ nir_lower_to_source_mods_block(nir_block *block,
             continue;
 
          nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src);
-         if (alu->src[i].abs) {
-            /* abs trumps both neg and abs, do nothing */
-         } else {
-            alu->src[i].negate = (alu->src[i].negate != parent->src[0].negate);
-            alu->src[i].abs |= parent->src[0].abs;
-         }
+         if (parent->src[0].negate)
+            alu_src_consume_negate(&alu->src[i]);
+         if (parent->src[0].abs)
+            alu_src_consume_abs(&alu->src[i]);
 
          for (int j = 0; j < 4; ++j) {
             if (!nir_alu_instr_channel_used(alu, i, j))