From 0a4b7f69c1634765824d94159c9bcd1249bf0010 Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Tue, 12 May 2026 12:17:48 +0200 Subject: [PATCH] pan/valhall: fuse_cmp skip when fusing the same instruction CSE can cause some cases where we had %3 = ICMP_OR %1, %2, 0 %4 = ICMP_OR %1, %2, 0 %5 = LSHIFT_AND %3, %4 To become %3 = ICMP_OR %1, %2, 0 %5 = LSHIFT_AND %3, %3 The va_fuse_cmp pass would try to rewrite this as %3 = ICMP_AND %1, %2, %3 But this is obviously wrong, we should not fuse the same instruction together. Fixes: 800a8614313 ("pan/bi: Fuse FCMP/ICMP on Valhall") Signed-off-by: Lorenzo Rossi Found-by: Ryan Zhang Reviewed-by: Ryan Zhang Reviewed-by: Eric R. Smith Part-of: --- src/panfrost/compiler/bifrost/valhall/va_optimize.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/panfrost/compiler/bifrost/valhall/va_optimize.c b/src/panfrost/compiler/bifrost/valhall/va_optimize.c index a0609601d4e..617bc329b8d 100644 --- a/src/panfrost/compiler/bifrost/valhall/va_optimize.c +++ b/src/panfrost/compiler/bifrost/valhall/va_optimize.c @@ -227,6 +227,13 @@ va_fuse_cmp(bi_context *ctx, bi_instr **lut, const BITSET_WORD *multiple, bi_instr *src0_ins = lut[I->src[0].value]; bi_instr *src1_ins = lut[I->src[1].value]; + /* %1 = FCMP(a, b) + * %2 = LSHIFT_X(%1, %1, 0) + * We cannot fold that. + */ + if (src0_ins == src1_ins) + return false; + enum va_cmp_type cmp_type = va_cmp_opcode_to_cmp_type(src0_ins->op); /* Expect both side to use the same form type */