nir/algebraic: Commute 1-fsat(a) to fsat(1-a) for all non-fmul instructions
[mesa.git] / src / compiler / nir / nir_search_helpers.h
index 9e03c610ece26e7c39de293ccf6248591cc071b1..631c65a8642259dcea07acc3dba268e1f8ac0048 100644 (file)
@@ -173,6 +173,22 @@ is_not_const(nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components,
    return !nir_src_is_const(instr->src[src].src);
 }
 
+static inline bool
+is_not_fmul(nir_alu_instr *instr, unsigned src,
+            UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)
+{
+   nir_alu_instr *src_alu =
+      nir_src_as_alu_instr(instr->src[src].src);
+
+   if (src_alu == NULL)
+      return true;
+
+   if (src_alu->op == nir_op_fneg)
+      return is_not_fmul(src_alu, 0, 0, NULL);
+
+   return src_alu->op != nir_op_fmul;
+}
+
 static inline bool
 is_used_once(nir_alu_instr *instr)
 {