return true;
}
+/**
+ * Exclusive compare with (0, 1).
+ *
+ * This differs from \c is_zero_to_one because that function tests 0 <= src <=
+ * 1 while this function tests 0 < src < 1.
+ */
+static inline bool
+is_gt_0_and_lt_1(nir_alu_instr *instr, unsigned src, unsigned num_components,
+ const uint8_t *swizzle)
+{
+ /* only constant srcs: */
+ if (!nir_src_is_const(instr->src[src].src))
+ return false;
+
+ for (unsigned i = 0; i < num_components; i++) {
+ switch (nir_op_infos[instr->op].input_types[src]) {
+ case nir_type_float: {
+ double val = nir_src_comp_as_float(instr->src[src].src, swizzle[i]);
+ if (isnan(val) || val <= 0.0f || val >= 1.0f)
+ return false;
+ break;
+ }
+ default:
+ return false;
+ }
+ }
+
+ return true;
+}
+
static inline bool
is_not_const_zero(nir_alu_instr *instr, unsigned src, unsigned num_components,
const uint8_t *swizzle)
}
static inline bool
-is_used_more_than_once(nir_alu_instr *instr)
+is_not_fmul(nir_alu_instr *instr, unsigned src,
+ UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)
{
- bool zero_if_use = list_empty(&instr->dest.dest.ssa.if_uses);
- bool zero_use = list_empty(&instr->dest.dest.ssa.uses);
+ nir_alu_instr *src_alu =
+ nir_src_as_alu_instr(instr->src[src].src);
- if (zero_use && zero_if_use)
- return false;
- else if (zero_use && list_is_singular(&instr->dest.dest.ssa.if_uses))
- return false;
- else if (zero_if_use && list_is_singular(&instr->dest.dest.ssa.uses))
- return false;
+ if (src_alu == NULL)
+ return true;
- 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