elk/cmod: Don't propagate from CMP to ADD if there is a write between

If either source of the CMP is modified before an appropriate ADD is
found, the ADD and the CMP will not have the same result.

No shader-db changes on any ELK platform. I suspect the problematic
cases only occur after scheduling has rearranged instructions. This is
likely the reason BRW didn't experience this problem until 09450faf.

Fixes: 020b0055e7 ("i965/fs: Propagate conditional modifiers from compares to adds")
Reviewed-by: Matt Turner <mattst88@gmail.com>
(cherry picked from commit da1fd9786b)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40092>
This commit is contained in:
Ian Romanick 2026-02-17 12:01:18 -08:00 committed by Eric Engestrom
parent 024c5de569
commit bfeb230f9b
2 changed files with 12 additions and 1 deletions

View file

@ -2214,7 +2214,7 @@
"description": "elk/cmod: Don't propagate from CMP to ADD if there is a write between",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "020b0055e7a085a6a8c961ad12ce94e58606a1ae",
"notes": null

View file

@ -109,6 +109,17 @@ cmod_propagate_cmp_to_add(const intel_device_info *devinfo, elk_bblock_t *block,
}
foreach_inst_in_block_reverse_starting_from(elk_fs_inst, scan_inst, inst) {
/* If either of the sources of the CMP is modified, the optimization
* cannot occur. This is the case even if the instruction modifying the
* value is an ADD of the appropriate form.
*/
if (regions_overlap(scan_inst->dst, scan_inst->size_written,
inst->src[0], inst->size_read(0)) ||
regions_overlap(scan_inst->dst, scan_inst->size_written,
inst->src[1], inst->size_read(1))) {
break;
}
if (scan_inst->opcode == ELK_OPCODE_ADD &&
!scan_inst->is_partial_write() &&
scan_inst->exec_size == inst->exec_size) {