From f39d1bc94543be4f75940e3632615644d20c28bd Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 25 Sep 2024 19:20:30 -0400 Subject: [PATCH] agx: add unit test for tricky backwards phi case Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/test/test-optimizer.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/asahi/compiler/test/test-optimizer.cpp b/src/asahi/compiler/test/test-optimizer.cpp index 23915ad0e9a..4012be1309b 100644 --- a/src/asahi/compiler/test/test-optimizer.cpp +++ b/src/asahi/compiler/test/test-optimizer.cpp @@ -181,6 +181,46 @@ TEST_F(Optimizer, FmulFsatF2F16) { agx_fmul_to(b, out, wx, wy)->saturate = true; }); } +TEST_F(Optimizer, FsatWithPhi) +{ + /* + * Construct the loop: + * + * A: + * ... + * + * B: + * phi ..., u + * u = wx * phi + * out = fsat u + * --> B + * + * This example shows that phi sources are read at the end of the + * predecessor, not at the start of the successor. If phis are not handled + * properly, the fsat would be fused incorrectly. + * + * This reproduces an issue hit in a Control shader. Astonishingly, it is not + * hit anywhere in CTS. + */ + NEGCASE32({ + agx_block *A = agx_start_block(b->shader); + agx_block *B = agx_test_block(b->shader); + + agx_block_add_successor(A, B); + agx_block_add_successor(B, B); + + b->cursor = agx_after_block(B); + agx_index u = agx_temp(b->shader, AGX_SIZE_32); + + agx_instr *phi = agx_phi_to(b, agx_temp(b->shader, AGX_SIZE_32), 2); + phi->src[0] = wx; + phi->src[1] = u; + + agx_fmul_to(b, u, wx, phi->dest[0]); + agx_fmov_to(b, out, u)->saturate = true; + }); +} + TEST_F(Optimizer, Copyprop) { CASE32(agx_fmul_to(b, out, wx, agx_mov(b, wy)), agx_fmul_to(b, out, wx, wy));