diff --git a/src/compiler/nir/nir_opt_sink.c b/src/compiler/nir/nir_opt_sink.c index bc028226b4f..4205b04e790 100644 --- a/src/compiler/nir/nir_opt_sink.c +++ b/src/compiler/nir/nir_opt_sink.c @@ -76,21 +76,25 @@ can_sink_instr(nir_instr *instr, nir_move_options options, bool *can_mov_out_of_ return options & nir_move_comparisons; /* Assuming that constants do not contribute to register pressure, it is - * beneficial to sink ALU instructions where all but one source is - * constant. Detect that case last. + * beneficial to sink ALU instructions where all non constant sources + * are the same. */ if (!(options & nir_move_alu)) return false; unsigned inputs = nir_op_infos[alu->op].num_inputs; - unsigned constant_inputs = 0; + int non_const = -1; for (unsigned i = 0; i < inputs; ++i) { if (is_constant_like(&alu->src[i].src)) - constant_inputs++; + continue; + else if (non_const < 0) + non_const = i; + else if (!nir_alu_srcs_equal(alu, alu, non_const, i)) + return false; } - return (constant_inputs + 1 >= inputs); + return true; } case nir_instr_type_intrinsic: { nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);