nak/opt_lop: Don't handle modifiers in dedup_srcs

The handling in dedup_srcs was incorrect because it would apply the
modifier from srcs[i] to the LUT without removing the modifier from the
instruction. We can fix and simplify this code by removing all modifiers
before the dedup_srcs() call, which we were doing immediately after the
call anyway.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13966
Fixes: 66c9c40f68 ("nak: Handle modifiers in dedup_srcs() in opt_lop()")
Reviewed-by: Seán de Búrca <sdeburca@fastmail.net>
Reviewed-by: Lorenzo Rossi <git@rossilorenzo.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38220>
(cherry picked from commit 041216e605)
This commit is contained in:
Mel Henning 2025-11-03 13:45:43 -05:00 committed by Eric Engestrom
parent c4c051b85e
commit 4ca61f20f3
2 changed files with 10 additions and 20 deletions

View file

@ -3254,7 +3254,7 @@
"description": "nak/opt_lop: Don't handle modifiers in dedup_srcs",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "66c9c40f68bcf738b1b5dd9a26d141d4c71e4522",
"notes": null

View file

@ -73,23 +73,11 @@ impl LopPass {
for i in 0..2 {
for j in (i + 1)..3 {
if srcs[i].src_ref == srcs[j].src_ref {
assert!(srcs[i].is_unmodified());
assert!(srcs[j].is_unmodified());
*op = LogicOp3::new_lut(&|x, y, z| {
let dup = [x, y, z][i];
let si = match srcs[i].src_mod {
SrcMod::None => dup,
SrcMod::BNot => !dup,
_ => panic!("Not a bitwise modifer"),
};
let sj = match srcs[j].src_mod {
SrcMod::None => dup,
SrcMod::BNot => !dup,
_ => panic!("Not a bitwise modifer"),
};
let mut s = [x, y, z];
s[i] = si;
s[j] = sj;
s[j] = s[i];
op.eval(s[0], s[1], s[2])
});
}
@ -220,17 +208,19 @@ impl LopPass {
}
fn opt_plop3(&mut self, op: &mut OpPLop3) {
self.dedup_srcs(&mut op.ops[0], &op.srcs);
self.dedup_srcs(&mut op.ops[1], &op.srcs);
// Replace unused sources with PT
for (i, src) in op.srcs.iter_mut().enumerate() {
if src.src_mod.is_bnot() {
op.ops[0].invert_src(i);
op.ops[1].invert_src(i);
src.src_mod = SrcMod::None;
}
}
self.dedup_srcs(&mut op.ops[0], &op.srcs);
self.dedup_srcs(&mut op.ops[1], &op.srcs);
// Replace unused sources with PT
for (i, src) in op.srcs.iter_mut().enumerate() {
if let Some(b) = src_as_bool(src) {
op.ops[0].fix_src(i, b);
op.ops[1].fix_src(i, b);