diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 4745e50b426..5ead743c8c3 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -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}, diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 5554f791bad..c4ea6d15552 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -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; diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h index 83cc9166c59..3d7aab3f02d 100644 --- a/src/compiler/nir/nir_search.h +++ b/src/compiler/nir/nir_search.h @@ -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;