nir/opt_generate_bfi: avoid trivial instructions
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

With the pass order shuffling, code like `(x & 0xf) + (x & 0xfffffff0)` gets
optimized to bitfield_select(0xF, x, x). But it would be much better to optimize
simply to x. nir_opt_algebraic would do that for us but we run this pass too
late for algebraic to save us from ourselves, so be smarter.

Observed on dEQP-GLES31.functional.compute.basic.image_atomic_op_local_size_8
with Jay, this saves an instruction there.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40956>
This commit is contained in:
Alyssa Rosenzweig 2026-04-14 12:04:23 -04:00 committed by Marge Bot
parent f137207108
commit 4b81cb6206

View file

@ -146,6 +146,14 @@ nir_opt_generate_bfi_instr(nir_builder *b,
b->cursor = nir_before_instr(&alu->instr);
/* Optimize with the rule bitfield_select(a, b, b) = b. We do this ourselves
* since we run late after nir_opt_algebraic.
*/
if (alu->def.num_components == 1 && nir_scalar_equal(insert[0], base[0])) {
nir_def_replace(&alu->def, nir_mov_scalar(b, insert[0]));
return true;
}
nir_def *mask_vec = nir_build_imm(b, alu->def.num_components, alu->def.bit_size, mask_cvals);
nir_def *insert_vec = nir_vec_scalars(b, insert, alu->def.num_components);
nir_def *base_vec = nir_vec_scalars(b, base, alu->def.num_components);