nir/search: reorder match_value to check constants first

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36760>
This commit is contained in:
Rhys Perry 2025-08-13 10:04:33 +01:00 committed by Marge Bot
parent 84fe10f939
commit 51dd513789
3 changed files with 9 additions and 2 deletions

View file

@ -215,6 +215,7 @@ class Value(object):
${'true' if val.nnan else 'false'},
${'true' if val.ninf else 'false'},
${'true' if val.contract else 'false'},
${'true' if len(val.sources) > 1 and isinstance(val.sources[1], Constant) else 'false'},
${val.swizzle},
${val.c_opcode()},
${val.comm_expr_idx}, ${val.comm_exprs},

View file

@ -426,11 +426,14 @@ match_expression(const nir_algebraic_table *table, const nir_search_expression *
bool matched = true;
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
/* If src1 of the search expression is a constant, check that first since it's faster. */
unsigned src_idx = i < 2 ? i ^ expr->src1_is_const : i;
/* 2src_commutative instructions that have 3 sources are only commutative
* in the first two sources. Source 2 is always source 2.
*/
if (!match_value(table, &state->table->values[expr->srcs[i]].value, instr,
i < 2 ? i ^ comm_op_flip : i,
if (!match_value(table, &state->table->values[expr->srcs[src_idx]].value, instr,
i < 2 ? src_idx ^ comm_op_flip : src_idx,
num_components, swizzle, state)) {
matched = false;
break;

View file

@ -151,6 +151,9 @@ typedef struct {
/** Replacement contracts an expression */
bool contract : 1;
/** Whether the second source is a nir_search_value_constant */
bool src1_is_const : 1;
/** Whether the use of the instruction should have a swizzle. */
int16_t swizzle : 5;