nir/opt_shrink_vectors: Remove shrinking of store intrinsics data source

This is done via nir_opt_shrink_stores.

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14480>
This commit is contained in:
Daniel Schürmann
2022-01-10 12:56:32 +00:00
parent 2dba7e6056
commit 2a92452a0e
8 changed files with 25 additions and 71 deletions

View File

@@ -2555,8 +2555,9 @@ radv_link_shaders(struct radv_pipeline *pipeline,
if (nir_lower_io_to_scalar_early(ordered_shaders[i], mask)) {
/* Optimize the new vector code and then remove dead vars */
nir_copy_prop(ordered_shaders[i]);
nir_opt_shrink_vectors(ordered_shaders[i],
!pipeline->device->instance->disable_shrink_image_store);
nir_opt_shrink_stores(ordered_shaders[i],
!pipeline->device->instance->disable_shrink_image_store);
nir_opt_shrink_vectors(ordered_shaders[i]);
if (ordered_shaders[i]->info.stage != last) {
/* Optimize swizzled movs of load_const for
@@ -3895,7 +3896,8 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_pipeline_layout
}
lower_to_scalar |=
nir_opt_shrink_vectors(nir[i], !device->instance->disable_shrink_image_store);
nir_opt_shrink_stores(nir[i], !device->instance->disable_shrink_image_store);
nir_opt_shrink_vectors(nir[i]);
if (lower_to_scalar)
nir_lower_alu_to_scalar(nir[i], NULL, NULL);

View File

@@ -192,8 +192,9 @@ radv_optimize_nir(const struct radv_device *device, struct nir_shader *shader,
NIR_PASS(progress, shader, nir_opt_algebraic);
NIR_PASS(progress, shader, nir_opt_undef);
NIR_PASS(progress, shader, nir_opt_shrink_vectors,
NIR_PASS(progress, shader, nir_opt_shrink_stores,
!device->instance->disable_shrink_image_store);
NIR_PASS(progress, shader, nir_opt_shrink_vectors);
if (shader->options->max_unroll_iterations) {
NIR_PASS(progress, shader, nir_opt_loop_unroll);
}

View File

@@ -5283,7 +5283,7 @@ bool nir_opt_phi_precision(nir_shader *shader);
bool nir_opt_shrink_stores(nir_shader *shader, bool shrink_image_store);
bool nir_opt_shrink_vectors(nir_shader *shader, bool shrink_image_store);
bool nir_opt_shrink_vectors(nir_shader *shader);
bool nir_opt_trivial_continues(nir_shader *shader);

View File

@@ -167,31 +167,7 @@ opt_shrink_vectors_alu(nir_builder *b, nir_alu_instr *instr)
}
static bool
opt_shrink_vectors_image_store(nir_builder *b, nir_intrinsic_instr *instr)
{
enum pipe_format format;
if (instr->intrinsic == nir_intrinsic_image_deref_store) {
nir_deref_instr *deref = nir_src_as_deref(instr->src[0]);
format = nir_deref_instr_get_variable(deref)->data.image.format;
} else {
format = nir_intrinsic_format(instr);
}
if (format == PIPE_FORMAT_NONE)
return false;
unsigned components = util_format_get_nr_components(format);
if (components >= instr->num_components)
return false;
nir_ssa_def *data = nir_channels(b, instr->src[3].ssa, BITSET_MASK(components));
nir_instr_rewrite_src(&instr->instr, &instr->src[3], nir_src_for_ssa(data));
instr->num_components = components;
return true;
}
static bool
opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, bool shrink_image_store)
opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr)
{
switch (instr->intrinsic) {
case nir_intrinsic_load_uniform:
@@ -208,17 +184,7 @@ opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, bool sh
case nir_intrinsic_load_global_constant:
case nir_intrinsic_load_kernel_input:
case nir_intrinsic_load_scratch:
case nir_intrinsic_store_output:
case nir_intrinsic_store_per_vertex_output:
case nir_intrinsic_store_ssbo:
case nir_intrinsic_store_shared:
case nir_intrinsic_store_global:
case nir_intrinsic_store_scratch:
break;
case nir_intrinsic_bindless_image_store:
case nir_intrinsic_image_deref_store:
case nir_intrinsic_image_store:
return shrink_image_store && opt_shrink_vectors_image_store(b, instr);
default:
return false;
}
@@ -226,29 +192,10 @@ opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr, bool sh
/* Must be a vectorized intrinsic that we can resize. */
assert(instr->num_components != 0);
if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
/* loads: Trim the dest to the used channels */
if (shrink_dest_to_read_mask(&instr->dest.ssa)) {
instr->num_components = instr->dest.ssa.num_components;
return true;
}
} else {
/* Stores: trim the num_components stored according to the write
* mask.
*/
unsigned write_mask = nir_intrinsic_write_mask(instr);
unsigned last_bit = util_last_bit(write_mask);
if (last_bit < instr->num_components && instr->src[0].is_ssa) {
nir_ssa_def *def = nir_channels(b, instr->src[0].ssa,
BITSET_MASK(last_bit));
nir_instr_rewrite_src(&instr->instr,
&instr->src[0],
nir_src_for_ssa(def));
instr->num_components = last_bit;
return true;
}
/* Trim the dest to the used channels */
if (shrink_dest_to_read_mask(&instr->dest.ssa)) {
instr->num_components = instr->dest.ssa.num_components;
return true;
}
return false;
@@ -267,7 +214,7 @@ opt_shrink_vectors_ssa_undef(nir_ssa_undef_instr *instr)
}
static bool
opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr, bool shrink_image_store)
opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr)
{
b->cursor = nir_before_instr(instr);
@@ -276,7 +223,7 @@ opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr, bool shrink_image_sto
return opt_shrink_vectors_alu(b, nir_instr_as_alu(instr));
case nir_instr_type_intrinsic:
return opt_shrink_vectors_intrinsic(b, nir_instr_as_intrinsic(instr), shrink_image_store);
return opt_shrink_vectors_intrinsic(b, nir_instr_as_intrinsic(instr));
case nir_instr_type_load_const:
return opt_shrink_vectors_load_const(nir_instr_as_load_const(instr));
@@ -292,7 +239,7 @@ opt_shrink_vectors_instr(nir_builder *b, nir_instr *instr, bool shrink_image_sto
}
bool
nir_opt_shrink_vectors(nir_shader *shader, bool shrink_image_store)
nir_opt_shrink_vectors(nir_shader *shader)
{
bool progress = false;
@@ -305,7 +252,7 @@ nir_opt_shrink_vectors(nir_shader *shader, bool shrink_image_store)
nir_foreach_block_reverse(block, function->impl) {
nir_foreach_instr_reverse(instr, block) {
progress |= opt_shrink_vectors_instr(&b, instr, shrink_image_store);
progress |= opt_shrink_vectors_instr(&b, instr);
}
}

View File

@@ -3084,7 +3084,8 @@ ntt_optimize_nir(struct nir_shader *s, struct pipe_screen *screen)
.robust_modes = 0,
};
NIR_PASS(progress, s, nir_opt_load_store_vectorize, &vectorize_opts);
NIR_PASS(progress, s, nir_opt_shrink_vectors, true);
NIR_PASS(progress, s, nir_opt_shrink_stores, true);
NIR_PASS(progress, s, nir_opt_shrink_vectors);
NIR_PASS(progress, s, nir_opt_trivial_continues);
NIR_PASS(progress, s, nir_opt_vectorize, ntt_should_vectorize_instr, NULL);
NIR_PASS(progress, s, nir_opt_undef);

View File

@@ -146,7 +146,8 @@ etna_optimize_loop(nir_shader *s)
NIR_PASS_V(s, nir_lower_vars_to_ssa);
progress |= OPT(s, nir_opt_copy_prop_vars);
progress |= OPT(s, nir_opt_shrink_vectors, true);
progress |= OPT(s, nir_opt_shrink_stores, true);
progress |= OPT(s, nir_opt_shrink_vectors);
progress |= OPT(s, nir_copy_prop);
progress |= OPT(s, nir_opt_dce);
progress |= OPT(s, nir_opt_cse);

View File

@@ -202,7 +202,8 @@ i915_optimize_nir(struct nir_shader *s)
true, true);
NIR_PASS(progress, s, nir_opt_algebraic);
NIR_PASS(progress, s, nir_opt_constant_folding);
NIR_PASS(progress, s, nir_opt_shrink_vectors, true);
NIR_PASS(progress, s, nir_opt_shrink_stores, true);
NIR_PASS(progress, s, nir_opt_shrink_vectors);
NIR_PASS(progress, s, nir_opt_trivial_continues);
NIR_PASS(progress, s, nir_opt_undef);
NIR_PASS(progress, s, nir_opt_loop_unroll);

View File

@@ -553,7 +553,8 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
if (is_scalar) {
OPT(nir_lower_alu_to_scalar, NULL, NULL);
} else {
OPT(nir_opt_shrink_vectors, true);
OPT(nir_opt_shrink_stores, true);
OPT(nir_opt_shrink_vectors);
}
OPT(nir_copy_prop);