nir/opt_varyings: change try_move_postdominator param to nir_instr type
We want more instructions to be movable, like load_deref(var, index = load_input). Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32424>
This commit is contained in:
@@ -3294,7 +3294,7 @@ gather_used_input_loads(nir_instr *instr,
|
|||||||
static bool
|
static bool
|
||||||
try_move_postdominator(struct linkage_info *linkage,
|
try_move_postdominator(struct linkage_info *linkage,
|
||||||
struct nir_use_dominance_state *postdom_state,
|
struct nir_use_dominance_state *postdom_state,
|
||||||
nir_alu_instr *postdom,
|
nir_instr *postdom,
|
||||||
nir_def *load_def,
|
nir_def *load_def,
|
||||||
nir_intrinsic_instr *first_load,
|
nir_intrinsic_instr *first_load,
|
||||||
nir_opt_varyings_progress *progress)
|
nir_opt_varyings_progress *progress)
|
||||||
@@ -3302,14 +3302,14 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
#define PRINT 0
|
#define PRINT 0
|
||||||
#if PRINT
|
#if PRINT
|
||||||
printf("Trying to move post-dom: ");
|
printf("Trying to move post-dom: ");
|
||||||
nir_print_instr(&postdom->instr, stdout);
|
nir_print_instr(postdom, stdout);
|
||||||
puts("");
|
puts("");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Gather the input loads used by the post-dominator using DFS. */
|
/* Gather the input loads used by the post-dominator using DFS. */
|
||||||
nir_intrinsic_instr *loads[NUM_SCALAR_SLOTS*8];
|
nir_intrinsic_instr *loads[NUM_SCALAR_SLOTS*8];
|
||||||
unsigned num_loads = 0;
|
unsigned num_loads = 0;
|
||||||
gather_used_input_loads(&postdom->instr, loads, &num_loads);
|
gather_used_input_loads(postdom, loads, &num_loads);
|
||||||
|
|
||||||
/* Clear the flag set by gather_used_input_loads. */
|
/* Clear the flag set by gather_used_input_loads. */
|
||||||
for (unsigned i = 0; i < num_loads; i++)
|
for (unsigned i = 0; i < num_loads; i++)
|
||||||
@@ -3343,7 +3343,7 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
|
|
||||||
#if PRINT
|
#if PRINT
|
||||||
printf("Post-dom accepted: ");
|
printf("Post-dom accepted: ");
|
||||||
nir_print_instr(&postdom->instr, stdout);
|
nir_print_instr(postdom, stdout);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -3365,7 +3365,8 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
struct scalar_slot *slot = &linkage->slot[slot_index];
|
struct scalar_slot *slot = &linkage->slot[slot_index];
|
||||||
nir_builder *b = &linkage->consumer_builder;
|
nir_builder *b = &linkage->consumer_builder;
|
||||||
b->cursor = nir_after_instr(load_def->parent_instr);
|
b->cursor = nir_after_instr(load_def->parent_instr);
|
||||||
unsigned alu_interp = postdom->instr.pass_flags & FLAG_INTERP_MASK;
|
nir_def *postdom_def = nir_instr_def(postdom);
|
||||||
|
unsigned alu_interp = postdom->pass_flags & FLAG_INTERP_MASK;
|
||||||
nir_def *new_input, *new_tes_loads[3];
|
nir_def *new_input, *new_tes_loads[3];
|
||||||
BITSET_WORD *mask;
|
BITSET_WORD *mask;
|
||||||
|
|
||||||
@@ -3382,13 +3383,14 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
if (linkage->consumer_stage == MESA_SHADER_FRAGMENT &&
|
if (linkage->consumer_stage == MESA_SHADER_FRAGMENT &&
|
||||||
alu_interp == FLAG_INTERP_CONVERGENT &&
|
alu_interp == FLAG_INTERP_CONVERGENT &&
|
||||||
!linkage->can_mix_convergent_flat_with_interpolated &&
|
!linkage->can_mix_convergent_flat_with_interpolated &&
|
||||||
((postdom->def.bit_size != 16 && postdom->def.bit_size != 32) ||
|
(postdom->type != nir_instr_type_alu ||
|
||||||
!(nir_op_infos[postdom->op].output_type & nir_type_float)))
|
(postdom_def->bit_size != 16 && postdom_def->bit_size != 32) ||
|
||||||
|
!(nir_op_infos[nir_instr_as_alu(postdom)->op].output_type & nir_type_float)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* NIR can't do 1-bit inputs. Convert them to a bigger size. */
|
/* NIR can't do 1-bit inputs. Convert them to a bigger size. */
|
||||||
assert(postdom->def.bit_size & (1 | 16 | 32));
|
assert(postdom_def->bit_size & (1 | 16 | 32));
|
||||||
unsigned new_bit_size = postdom->def.bit_size;
|
unsigned new_bit_size = postdom_def->bit_size;
|
||||||
|
|
||||||
if (new_bit_size == 1) {
|
if (new_bit_size == 1) {
|
||||||
assert(alu_interp == FLAG_INTERP_CONVERGENT ||
|
assert(alu_interp == FLAG_INTERP_CONVERGENT ||
|
||||||
@@ -3578,7 +3580,7 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(i == 3);
|
assert(i == 3);
|
||||||
assert(postdom->def.bit_size != 1);
|
assert(postdom_def->bit_size != 1);
|
||||||
|
|
||||||
slot->consumer.tes_interp_load =
|
slot->consumer.tes_interp_load =
|
||||||
nir_instr_as_alu(new_input->parent_instr);
|
nir_instr_as_alu(new_input->parent_instr);
|
||||||
@@ -3588,18 +3590,18 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
nir_instr_as_intrinsic(new_input->parent_instr);
|
nir_instr_as_intrinsic(new_input->parent_instr);
|
||||||
|
|
||||||
/* The input is a bigger type even if the post-dominator is boolean. */
|
/* The input is a bigger type even if the post-dominator is boolean. */
|
||||||
if (postdom->def.bit_size == 1)
|
if (postdom_def->bit_size == 1)
|
||||||
new_input = nir_ine_imm(b, new_input, 0);
|
new_input = nir_ine_imm(b, new_input, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
nir_def_rewrite_uses(&postdom->def, new_input);
|
nir_def_rewrite_uses(postdom_def, new_input);
|
||||||
|
|
||||||
/* Clone the post-dominator at the end of the block in the producer
|
/* Clone the post-dominator at the end of the block in the producer
|
||||||
* where the output stores are.
|
* where the output stores are.
|
||||||
*/
|
*/
|
||||||
b = &linkage->producer_builder;
|
b = &linkage->producer_builder;
|
||||||
b->cursor = nir_after_block_before_jump(block);
|
b->cursor = nir_after_block_before_jump(block);
|
||||||
nir_def *producer_clone = clone_ssa(linkage, b, &postdom->def);
|
nir_def *producer_clone = clone_ssa(linkage, b, postdom_def);
|
||||||
|
|
||||||
/* Boolean post-dominators are upcast in the producer because we can't
|
/* Boolean post-dominators are upcast in the producer because we can't
|
||||||
* use 1-bit outputs.
|
* use 1-bit outputs.
|
||||||
@@ -3652,7 +3654,7 @@ try_move_postdominator(struct linkage_info *linkage,
|
|||||||
struct list_node, head)->instr->instr;
|
struct list_node, head)->instr->instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nir_instr_dominates_use(postdom_state, &postdom->instr, load)) {
|
if (nir_instr_dominates_use(postdom_state, postdom, load)) {
|
||||||
list_inithead(&slot->consumer.loads);
|
list_inithead(&slot->consumer.loads);
|
||||||
|
|
||||||
/* Remove stores. (transform feedback is allowed here, just not
|
/* Remove stores. (transform feedback is allowed here, just not
|
||||||
@@ -3912,8 +3914,7 @@ backward_inter_shader_code_motion(struct linkage_info *linkage,
|
|||||||
/* Add the post-dominator to the list unless it's been added already. */
|
/* Add the post-dominator to the list unless it's been added already. */
|
||||||
if (movable_postdom &&
|
if (movable_postdom &&
|
||||||
!(movable_postdom->pass_flags & FLAG_POST_DOMINATOR_PROCESSED)) {
|
!(movable_postdom->pass_flags & FLAG_POST_DOMINATOR_PROCESSED)) {
|
||||||
if (try_move_postdominator(linkage, postdom_state,
|
if (try_move_postdominator(linkage, postdom_state, movable_postdom,
|
||||||
nir_instr_as_alu(movable_postdom),
|
|
||||||
load_def, movable_loads[i].first_load,
|
load_def, movable_loads[i].first_load,
|
||||||
progress)) {
|
progress)) {
|
||||||
/* Moving only one postdominator can change the IR enough that
|
/* Moving only one postdominator can change the IR enough that
|
||||||
|
Reference in New Issue
Block a user