From fb55d222fc1ce1012532713959f4ba8b2fb6483b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 15 Apr 2026 17:21:38 -0400 Subject: [PATCH] nir/opt_reassociate: fix exactness bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For an inexact-associative operation (fadd or fmul), can_reassociate ensures the root of the chain is inexact to allow reassociating. However, build_chain just checks for opcodes to match up after, although we do sum up exactness across the chain. Although an Effort Was Made, it still seems incorrect to reassociate %3 = fadd! %0, %1 %4 = fadd %3, %2 to instead be (ex.) %3 = fadd! %0, %2 %4 = fadd! %3, %1 Closes: #14418 Fixes: e0b0f7e73c8 ("nir: add ALU reassocation pass") Signed-off-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák (cherry picked from commit 0c49738211fe86e6a7b342bd85152389412f8e47) Part-of: --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_reassociate.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index d0b1be250c0..73b286ee622 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -574,7 +574,7 @@ "description": "nir/opt_reassociate: fix exactness bug", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e0b0f7e73c88f63472cdaedf01b428e6a824d5de", "notes": null diff --git a/src/compiler/nir/nir_opt_reassociate.c b/src/compiler/nir/nir_opt_reassociate.c index 8ec323c363d..c71ba933287 100644 --- a/src/compiler/nir/nir_opt_reassociate.c +++ b/src/compiler/nir/nir_opt_reassociate.c @@ -227,6 +227,7 @@ build_chain(struct chain *c, nir_scalar def, unsigned reserved_count) unsigned reserved_plus_remaining = reserved_count + remaining; if (nir_scalar_is_alu(src) && nir_scalar_alu_op(src) == alu->op && + can_reassociate(nir_def_as_alu(src.def)) && list_is_singular(&src.def->uses) && c->length + reserved_plus_remaining + 2 <= MAX_CHAIN_LENGTH) {