mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 11:20:11 +01:00
nir/builder: Don't emit no-op swizzles
The nir_swizzle helper is used some on it's own but it's also called by nir_channel and nir_channels which are used everywhere. It's pretty quick to check while we're walking the swizzle anyway whether or not it's an identity swizzle. If it is, we now don't bother emitting the instruction. Sure, copy-prop will clean it up for us but there's no sense making more work for the optimizer than we have to. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
parent
724371c6b9
commit
743700be1f
1 changed files with 9 additions and 1 deletions
|
|
@ -497,8 +497,16 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, const unsigned *swiz,
|
||||||
assert(num_components <= NIR_MAX_VEC_COMPONENTS);
|
assert(num_components <= NIR_MAX_VEC_COMPONENTS);
|
||||||
nir_alu_src alu_src = { NIR_SRC_INIT };
|
nir_alu_src alu_src = { NIR_SRC_INIT };
|
||||||
alu_src.src = nir_src_for_ssa(src);
|
alu_src.src = nir_src_for_ssa(src);
|
||||||
for (unsigned i = 0; i < num_components && i < NIR_MAX_VEC_COMPONENTS; i++)
|
|
||||||
|
bool is_identity_swizzle = true;
|
||||||
|
for (unsigned i = 0; i < num_components && i < NIR_MAX_VEC_COMPONENTS; i++) {
|
||||||
|
if (swiz[i] != i)
|
||||||
|
is_identity_swizzle = false;
|
||||||
alu_src.swizzle[i] = swiz[i];
|
alu_src.swizzle[i] = swiz[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num_components == src->num_components && is_identity_swizzle)
|
||||||
|
return src;
|
||||||
|
|
||||||
return use_fmov ? nir_fmov_alu(build, alu_src, num_components) :
|
return use_fmov ? nir_fmov_alu(build, alu_src, num_components) :
|
||||||
nir_imov_alu(build, alu_src, num_components);
|
nir_imov_alu(build, alu_src, num_components);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue