brw/copy: Perform constant folding with constant propagation

No shader-db or fossil-db changes on any Intel platform.

v2: Simlify the logic for when to try constant folding. Do
commute_immediates before constant folding. Both suggested by Ken.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31729>
This commit is contained in:
Ian Romanick 2024-10-10 14:09:04 -07:00 committed by Marge Bot
parent 2cc1575a31
commit ac64b78f1f

View file

@ -1318,7 +1318,7 @@ opt_copy_propagation_local(const brw_compiler *compiler, linear_ctx *lin_ctx,
foreach_inst_in_block(fs_inst, inst, block) {
/* Try propagating into this instruction. */
bool instruction_progress = false;
bool constant_progress = false;
for (int i = inst->sources - 1; i >= 0; i--) {
if (inst->src[i].file != VGRF)
continue;
@ -1328,22 +1328,23 @@ opt_copy_propagation_local(const brw_compiler *compiler, linear_ctx *lin_ctx,
++iter) {
if ((*iter)->src.file == IMM) {
if (try_constant_propagate(inst, *iter, i)) {
instruction_progress = true;
constant_progress = true;
break;
}
} else {
if (try_copy_propagate(compiler, inst, *iter, i, alloc,
max_polygons)) {
instruction_progress = true;
progress = true;
break;
}
}
}
}
if (instruction_progress) {
progress = true;
if (constant_progress) {
commute_immediates(inst);
brw_constant_fold_instruction(compiler->devinfo, inst);
progress = true;
}
/* kill the destination from the ACP */
@ -1803,7 +1804,7 @@ brw_fs_opt_copy_propagation_defs(fs_visitor &s)
foreach_block_and_inst_safe(block, fs_inst, inst, s.cfg) {
/* Try propagating into this instruction. */
bool instruction_progress = false;
bool constant_progress = false;
for (int i = inst->sources - 1; i >= 0; i--) {
fs_inst *def = defs.get(inst->src[i]);
@ -1822,7 +1823,7 @@ brw_fs_opt_copy_propagation_defs(fs_visitor &s)
inst, i, s.max_polygons);
if (source_progress) {
instruction_progress = true;
progress = true;
++uses_deleted[def->dst.nr];
if (defs.get_use_count(def->dst) == uses_deleted[def->dst.nr])
def->remove(defs.get_block(def->dst), true);
@ -1836,8 +1837,10 @@ brw_fs_opt_copy_propagation_defs(fs_visitor &s)
find_value_for_offset(def, inst->src[i], inst->size_read(i));
if (val.file == IMM) {
source_progress =
try_constant_propagate_def(def, val, inst, i);
if (try_constant_propagate_def(def, val, inst, i)) {
source_progress = true;
constant_progress = true;
}
} else if (val.file == VGRF ||
val.file == ATTR || val.file == UNIFORM ||
(val.file == FIXED_GRF && val.is_contiguous())) {
@ -1847,7 +1850,7 @@ brw_fs_opt_copy_propagation_defs(fs_visitor &s)
}
if (source_progress) {
instruction_progress = true;
progress = true;
++uses_deleted[def->dst.nr];
/* We can copy propagate through an instruction like
@ -1863,9 +1866,9 @@ brw_fs_opt_copy_propagation_defs(fs_visitor &s)
}
}
if (instruction_progress) {
progress = true;
if (constant_progress) {
commute_immediates(inst);
brw_constant_fold_instruction(s.compiler->devinfo, inst);
}
}