nir_mov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
{
assert(!src.abs && !src.negate);
+ if (src.src.is_ssa && src.src.ssa->num_components == num_components) {
+ bool any_swizzles = false;
+ for (unsigned i = 0; i < num_components; i++) {
+ if (src.swizzle[i] != i)
+ any_swizzles = true;
+ }
+ if (!any_swizzles)
+ return src.src.ssa;
+ }
+
nir_alu_instr *mov = nir_alu_instr_create(build->shader, nir_op_mov);
nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components,
nir_src_bit_size(src.src), NULL);
instr->dest.dest.ssa.bit_size,
&state, &instr->instr);
- /* Inserting a mov may be unnecessary. However, it's much easier to
- * simply let copy propagation clean this up than to try to go through
- * and rewrite swizzles ourselves.
+ /* Note that NIR builder will elide the MOV if it's a no-op, which may
+ * allow more work to be done in a single pass through algebraic.
*/
nir_ssa_def *ssa_val =
nir_mov_alu(build, val, instr->dest.dest.ssa.num_components);