unsigned bias;
};
+static bool
+mir_args_ssa(nir_ssa_scalar s, unsigned count)
+{
+ nir_alu_instr *alu = nir_instr_as_alu(s.def->parent_instr);
+ assert(count <= nir_op_infos[alu->op].num_inputs);
+
+ for (unsigned i = 0; i < count; ++i) {
+ if (!alu->src[i].src.is_ssa)
+ return false;
+ }
+
+ return true;
+}
+
/* Matches a constant in either slot and moves it to the bias */
static void
if (!address->B.def || !nir_ssa_scalar_is_alu(address->B))
return;
+ if (!mir_args_ssa(address->B, 2))
+ return;
+
nir_op op = nir_ssa_scalar_alu_op(address->B);
if (op != nir_op_iadd) return;
if (!address->B.def || !nir_ssa_scalar_is_alu(address->B))
return;
+ if (!mir_args_ssa(address->B, 1))
+ return;
+
nir_op op = nir_ssa_scalar_alu_op(address->B);
if (op != nir_op_u2u64) return;
nir_ssa_scalar arg = nir_ssa_scalar_chase_alu_src(address->B, 0);
if (!address->B.def || !nir_ssa_scalar_is_alu(address->B))
return;
+ if (!mir_args_ssa(address->B, 2))
+ return;
+
nir_op op = nir_ssa_scalar_alu_op(address->B);
if (op != nir_op_ishl) return;
nir_ssa_scalar op1 = nir_ssa_scalar_chase_alu_src(address->B, 0);
if (address->A.def && nir_ssa_scalar_is_alu(address->A)) {
nir_op op = nir_ssa_scalar_alu_op(address->A);
- if (op == nir_op_mov)
+ if (op == nir_op_mov && mir_args_ssa(address->A, 1))
address->A = nir_ssa_scalar_chase_alu_src(address->A, 0);
}
if (address->B.def && nir_ssa_scalar_is_alu(address->B)) {
nir_op op = nir_ssa_scalar_alu_op(address->B);
- if (op == nir_op_mov)
+ if (op == nir_op_mov && mir_args_ssa(address->B, 1))
address->B = nir_ssa_scalar_chase_alu_src(address->B, 0);
}
}