<div dir="ltr"><div>Looks correct.</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 12, 2018 at 2:17 AM Gert Wollny <<a href="mailto:gw.fossdev@gmail.com">gw.fossdev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Gert Wollny <<a href="mailto:gert.wollny@collabora.com" target="_blank">gert.wollny@collabora.com</a>><br>
<br>
Some hardware supports source mods only for float operations. Make it<br>
possible to skip lowering to source mods in these cases.<br>
<br>
v2: use option flags instead of a boolean (Jason Ekstrand)<br>
<br>
Signed-off-by: Gert Wollny <<a href="mailto:gert.wollny@collabora.com" target="_blank">gert.wollny@collabora.com</a>><br>
---<br>
 src/compiler/nir/nir.h                      | 10 ++-<br>
 src/compiler/nir/nir_lower_to_source_mods.c | 78 +++++++++++++--------<br>
 src/intel/compiler/brw_nir.c                |  2 +-<br>
 3 files changed, 58 insertions(+), 32 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index dc3c729dee..c4601ed218 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -3013,7 +3013,15 @@ typedef struct nir_lower_bitmap_options {<br>
 void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *options);<br>
<br>
 bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned ssbo_offset);<br>
-bool nir_lower_to_source_mods(nir_shader *shader);<br>
+<br>
+typedef enum  {<br>
+   nir_lower_int_source_mods = 1 << 0,<br>
+   nir_lower_float_source_mods = 1 << 1,<br>
+   nir_lower_all_source_mods = (1 << 2) - 1<br>
+} nir_lower_to_source_mods_flags;<br>
+<br>
+<br>
+bool nir_lower_to_source_mods(nir_shader *shader, nir_lower_to_source_mods_flags options);<br>
<br>
 bool nir_lower_gs_intrinsics(nir_shader *shader);<br>
<br>
diff --git a/src/compiler/nir/nir_lower_to_source_mods.c b/src/compiler/nir/nir_lower_to_source_mods.c<br>
index 077ca53704..657bf8a3d7 100644<br>
--- a/src/compiler/nir/nir_lower_to_source_mods.c<br>
+++ b/src/compiler/nir/nir_lower_to_source_mods.c<br>
@@ -34,7 +34,8 @@<br>
  */<br>
<br>
 static bool<br>
-nir_lower_to_source_mods_block(nir_block *block)<br>
+nir_lower_to_source_mods_block(nir_block *block,<br>
+                               nir_lower_to_source_mods_flags options)<br>
 {<br>
    bool progress = false;<br>
<br>
@@ -58,10 +59,14 @@ nir_lower_to_source_mods_block(nir_block *block)<br>
<br>
          switch (nir_alu_type_get_base_type(nir_op_infos[alu->op].input_types[i])) {<br>
          case nir_type_float:<br>
+            if (!(options & nir_lower_float_source_mods))<br>
+               continue;<br>
             if (parent->op != nir_op_fmov)<br>
                continue;<br>
             break;<br>
          case nir_type_int:<br>
+            if (!(options & nir_lower_int_source_mods))<br>
+               continue;<br>
             if (parent->op != nir_op_imov)<br>
                continue;<br>
             break;<br>
@@ -97,33 +102,41 @@ nir_lower_to_source_mods_block(nir_block *block)<br>
          progress = true;<br>
       }<br>
<br>
-      switch (alu->op) {<br>
-      case nir_op_fsat:<br>
-         alu->op = nir_op_fmov;<br>
-         alu->dest.saturate = true;<br>
-         break;<br>
-      case nir_op_ineg:<br>
-         alu->op = nir_op_imov;<br>
-         alu->src[0].negate = !alu->src[0].negate;<br>
-         break;<br>
-      case nir_op_fneg:<br>
-         alu->op = nir_op_fmov;<br>
-         alu->src[0].negate = !alu->src[0].negate;<br>
-         break;<br>
-      case nir_op_iabs:<br>
-         alu->op = nir_op_imov;<br>
-         alu->src[0].abs = true;<br>
-         alu->src[0].negate = false;<br>
-         break;<br>
-      case nir_op_fabs:<br>
-         alu->op = nir_op_fmov;<br>
-         alu->src[0].abs = true;<br>
-         alu->src[0].negate = false;<br>
-         break;<br>
-      default:<br>
-         break;<br>
+      if (options & nir_lower_float_source_mods) {<br>
+         switch (alu->op) {<br>
+         case nir_op_fsat:<br>
+            alu->op = nir_op_fmov;<br>
+            alu->dest.saturate = true;<br>
+            break;<br>
+         case nir_op_fneg:<br>
+            alu->op = nir_op_fmov;<br>
+            alu->src[0].negate = !alu->src[0].negate;<br>
+            break;<br>
+         case nir_op_fabs:<br>
+            alu->op = nir_op_fmov;<br>
+            alu->src[0].abs = true;<br>
+            alu->src[0].negate = false;<br>
+            break;<br>
+         default:<br>
+            break;<br>
+         }<br>
       }<br>
<br>
+      if (options & nir_lower_int_source_mods) {<br>
+         switch (alu->op) {<br>
+         case nir_op_ineg:<br>
+            alu->op = nir_op_imov;<br>
+            alu->src[0].negate = !alu->src[0].negate;<br>
+            break;<br>
+         case nir_op_iabs:<br>
+            alu->op = nir_op_imov;<br>
+            alu->src[0].abs = true;<br>
+            alu->src[0].negate = false;<br>
+            break;<br>
+         default:<br>
+            break;<br>
+         }<br>
+      }<br>
       /* We've covered sources.  Now we're going to try and saturate the<br>
        * destination if we can.<br>
        */<br>
@@ -136,6 +149,9 @@ nir_lower_to_source_mods_block(nir_block *block)<br>
           nir_type_float)<br>
          continue;<br>
<br>
+      if (!(options & nir_lower_float_source_mods))<br>
+         continue;<br>
+<br>
       if (!list_empty(&alu->dest.dest.ssa.if_uses))<br>
          continue;<br>
<br>
@@ -185,12 +201,13 @@ nir_lower_to_source_mods_block(nir_block *block)<br>
 }<br>
<br>
 static bool<br>
-nir_lower_to_source_mods_impl(nir_function_impl *impl)<br>
+nir_lower_to_source_mods_impl(nir_function_impl *impl,<br>
+                              nir_lower_to_source_mods_flags options)<br>
 {<br>
    bool progress = false;<br>
<br>
    nir_foreach_block(block, impl) {<br>
-      progress |= nir_lower_to_source_mods_block(block);<br>
+      progress |= nir_lower_to_source_mods_block(block, options);<br>
    }<br>
<br>
    if (progress)<br>
@@ -201,13 +218,14 @@ nir_lower_to_source_mods_impl(nir_function_impl *impl)<br>
 }<br>
<br>
 bool<br>
-nir_lower_to_source_mods(nir_shader *shader)<br>
+nir_lower_to_source_mods(nir_shader *shader,<br>
+                         nir_lower_to_source_mods_flags options)<br>
 {<br>
    bool progress = false;<br>
<br>
    nir_foreach_function(function, shader) {<br>
       if (function->impl) {<br>
-         progress |= nir_lower_to_source_mods_impl(function->impl);<br>
+         progress |= nir_lower_to_source_mods_impl(function->impl, options);<br>
       }<br>
    }<br>
<br>
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c<br>
index cf5a4a96d6..eb37f739f7 100644<br>
--- a/src/intel/compiler/brw_nir.c<br>
+++ b/src/intel/compiler/brw_nir.c<br>
@@ -793,7 +793,7 @@ brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler,<br>
<br>
    OPT(nir_opt_algebraic_late);<br>
<br>
-   OPT(nir_lower_to_source_mods);<br>
+   OPT(nir_lower_to_source_mods, nir_lower_all_source_mods);<br>
    OPT(nir_copy_prop);<br>
    OPT(nir_opt_dce);<br>
    OPT(nir_opt_move_comparisons);<br>
-- <br>
2.18.1<br>
<br>
</blockquote></div>