~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/compiler/nir/nir_opt_copy_propagate.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
}
58
58
 
59
59
static bool
60
 
rewrite_to_vec(nir_function_impl *impl, nir_alu_instr *mov, nir_alu_instr *vec)
 
60
rewrite_to_vec(nir_alu_instr *mov, nir_alu_instr *vec)
61
61
{
62
62
   if (mov->op != nir_op_mov)
63
63
      return false;
64
64
 
65
 
   nir_builder b;
66
 
   nir_builder_init(&b, impl);
67
 
   b.cursor = nir_after_instr(&mov->instr);
 
65
   nir_builder b = nir_builder_at(nir_after_instr(&mov->instr));
68
66
 
69
67
   unsigned num_comp = mov->dest.dest.ssa.num_components;
70
68
   nir_alu_instr *new_vec = nir_alu_instr_create(b.shader, nir_op_vec(num_comp));
81
79
}
82
80
 
83
81
static bool
84
 
copy_propagate_alu(nir_function_impl *impl, nir_alu_src *src, nir_alu_instr *copy)
 
82
copy_propagate_alu(nir_alu_src *src, nir_alu_instr *copy)
85
83
{
86
84
   nir_ssa_def *def = NULL;
87
85
   nir_alu_instr *user = nir_instr_as_alu(src->src.parent_instr);
99
97
 
100
98
      for (unsigned i = 1; i < num_comp; i++) {
101
99
         if (copy->src[src->swizzle[i]].src.ssa != def)
102
 
            return rewrite_to_vec(impl, user, copy);
 
100
            return rewrite_to_vec(user, copy);
103
101
      }
104
102
 
105
103
      for (unsigned i = 0; i < num_comp; i++)
123
121
}
124
122
 
125
123
static bool
126
 
copy_prop_instr(nir_function_impl *impl, nir_instr *instr)
 
124
copy_prop_instr(nir_instr *instr)
127
125
{
128
126
   if (instr->type != nir_instr_type_alu)
129
127
      return false;
137
135
 
138
136
   nir_foreach_use_including_if_safe(src, &mov->dest.dest.ssa) {
139
137
      if (!src->is_if && src->parent_instr->type == nir_instr_type_alu)
140
 
         progress |= copy_propagate_alu(impl, container_of(src, nir_alu_src, src), mov);
 
138
         progress |= copy_propagate_alu(container_of(src, nir_alu_src, src), mov);
141
139
      else
142
140
         progress |= copy_propagate(src, mov);
143
141
   }
155
153
 
156
154
   nir_foreach_block(block, impl) {
157
155
      nir_foreach_instr_safe(instr, block) {
158
 
         progress |= copy_prop_instr(impl, instr);
 
156
         progress |= copy_prop_instr(instr);
159
157
      }
160
158
   }
161
159
 
174
172
{
175
173
   bool progress = false;
176
174
 
177
 
   nir_foreach_function(function, shader) {
178
 
      if (function->impl && nir_copy_prop_impl(function->impl))
 
175
   nir_foreach_function_impl(impl, shader) {
 
176
      if (nir_copy_prop_impl(impl))
179
177
         progress = true;
180
178
   }
181
179