From 10aea75a3fe0ad9647c7c5e6ca011c98cf5b9e98 Mon Sep 17 00:00:00 2001 From: Christoph Pillmayer Date: Wed, 15 Apr 2026 08:08:17 +0200 Subject: [PATCH] pan/bi: Fix source swizzle in bi_repair_ssa Repairing SSA was creating invalid PHI nodes with source swizzles != BI_SWIZZLE_H01. PHI sources can't have non-identity swizzles. In most cases the repair logic only replaces sources, in which case the swizzle is taken from the old source that is getting replaced. However, in add_phi_operands there is no old source because the phi is new, and so the result from resolve_read is assigned directly. This falsely carries over the destination swizzle to the source. Since it never makes sense for resolve_read to carry over the swizzle from the instruction writing the value, we can make it so that resolve_read always returns the identity swizzle on indices. resolve_read returns one of: - An index stored by record_write - An index created by bi_temp_like - The result of a recursive resolve_read call bi_temp_like already correctly sets the swizzle to H01. Setting it in record_write leads to both base cases returning the desired swizzle. Fixes: dd94d183 ("pan/bi: Fixup bi_repair_ssa.c for bi") Reviewed-by: Lorenzo Rossi Reviewed-by: Eric R. Smith (cherry picked from commit fcfc580f67d2a5f1a5cb84072d4fd028661f01a0) Part-of: --- .pick_status.json | 2 +- src/panfrost/compiler/bifrost/bi_repair_ssa.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 95cfd412cd6..a975eff0724 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2344,7 +2344,7 @@ "description": "pan/bi: Fix source swizzle in bi_repair_ssa", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "dd94d1833f6cd05a123ca4aa038a6547685ec20b", "notes": null diff --git a/src/panfrost/compiler/bifrost/bi_repair_ssa.c b/src/panfrost/compiler/bifrost/bi_repair_ssa.c index 583fefae6c6..90990640246 100644 --- a/src/panfrost/compiler/bifrost/bi_repair_ssa.c +++ b/src/panfrost/compiler/bifrost/bi_repair_ssa.c @@ -50,6 +50,14 @@ record_write(struct repair_ctx *ctx, bi_block *block, unsigned node, bi_index val) { assert(node < ctx->n); + + /* The value always gets used as a source, where we don't want the + * destination "swizzle" and other modifiers that are applied on write. + */ + val.swizzle = BI_SWIZZLE_H01; + val.neg = false; + val.abs = false; + struct hash_table_u64 *defs = repair_block(ctx, block)->defs; _mesa_hash_table_u64_insert(defs, node, ralloc_memdup(defs, &val, sizeof(val))); @@ -106,6 +114,7 @@ resolve_read(struct repair_ctx *ctx, bi_block *block, bi_index node) } assert(!bi_is_null(val)); + assert(val.swizzle == BI_SWIZZLE_H01); record_write(ctx, block, node.value, val); return val; }