From ac64b78f1f38a0dea0e7d21bc58b96a9ab061c4e Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 10 Oct 2024 14:09:04 -0700 Subject: [PATCH] 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 Part-of: --- .../compiler/brw_fs_copy_propagation.cpp | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/intel/compiler/brw_fs_copy_propagation.cpp b/src/intel/compiler/brw_fs_copy_propagation.cpp index 84369d97f2f..92c00760986 100644 --- a/src/intel/compiler/brw_fs_copy_propagation.cpp +++ b/src/intel/compiler/brw_fs_copy_propagation.cpp @@ -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); } }