mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-20 16:00:08 +01:00
nir/builder: add option to immediately constant-fold ALU instructions upon insertion
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37195>
This commit is contained in:
parent
280eb2d689
commit
f61cd64af8
4 changed files with 16 additions and 3 deletions
|
|
@ -6240,6 +6240,8 @@ bool nir_opt_algebraic_integer_promotion(nir_shader *shader);
|
|||
bool nir_opt_reassociate_matrix_mul(nir_shader *shader);
|
||||
bool nir_opt_constant_folding(nir_shader *shader);
|
||||
|
||||
nir_def *nir_try_constant_fold_alu(nir_builder *b, nir_alu_instr *alu);
|
||||
|
||||
/* Try to combine a and b into a. Return true if combination was possible,
|
||||
* which will result in b being removed by the pass. Return false if
|
||||
* combination wasn't possible.
|
||||
|
|
|
|||
|
|
@ -123,6 +123,14 @@ nir_builder_alu_instr_finish_and_insert(nir_builder *build, nir_alu_instr *instr
|
|||
nir_def_init(&instr->instr, &instr->def, num_components,
|
||||
bit_size);
|
||||
|
||||
if (build->constant_fold_alu) {
|
||||
nir_def *new_def = nir_try_constant_fold_alu(build, instr);
|
||||
if (new_def) {
|
||||
nir_instr_free(&instr->instr);
|
||||
return new_def;
|
||||
}
|
||||
}
|
||||
|
||||
nir_builder_instr_insert(build, &instr->instr);
|
||||
|
||||
return &instr->def;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ typedef struct nir_builder {
|
|||
/* Whether new ALU instructions will be marked "exact" */
|
||||
bool exact;
|
||||
|
||||
/* Whether new ALU instruction will be constanst-folded if possible. */
|
||||
bool constant_fold_alu;
|
||||
|
||||
/* Float_controls2 bits. See nir_alu_instr for details. */
|
||||
uint32_t fp_fast_math;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ struct constant_fold_state {
|
|||
bool has_indirect_load_const;
|
||||
};
|
||||
|
||||
static nir_def *
|
||||
try_fold_alu(nir_builder *b, nir_alu_instr *alu)
|
||||
nir_def *
|
||||
nir_try_constant_fold_alu(nir_builder *b, nir_alu_instr *alu)
|
||||
{
|
||||
nir_const_value src[NIR_ALU_MAX_INPUTS][NIR_MAX_VEC_COMPONENTS];
|
||||
|
||||
|
|
@ -437,7 +437,7 @@ try_fold_instr(nir_builder *b, nir_instr *instr, void *_state)
|
|||
{
|
||||
switch (instr->type) {
|
||||
case nir_instr_type_alu:
|
||||
return try_fold_alu(b, nir_instr_as_alu(instr));
|
||||
return nir_try_constant_fold_alu(b, nir_instr_as_alu(instr));
|
||||
case nir_instr_type_intrinsic:
|
||||
return try_fold_intrinsic(b, nir_instr_as_intrinsic(instr), _state);
|
||||
case nir_instr_type_tex:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue