From 3d89c681dd6747872869b3e5588d1cc77c1b3a2c Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sat, 28 Nov 2026 13:42:13 -0500 Subject: [PATCH] asahi/compiler: skip non-register PHI sources before class assert in agx_validate_ra In validate_block(), non-loop-header PHI validation asserted ra_class_for_index(src) == cls before checking if (!src.has_reg). When a spilled PHI destination (RA_MEM) has an immediate or other non-register source (memory == 0, has_reg == false), ra_class_for_index(src) returned RA_GPR and tripped the assertion on debug/assertion-enabled builds (e.g., spilling compute shaders in llama.cpp Vulkan pp512). Check !src.has_reg before asserting the register class, and add a unit test covering a spilled non-loop-header PHI with an immediate source. Signed-off-by: Satya Benson --- src/asahi/compiler/agx_validate_ra.c | 2 +- .../test/test-native-form-regressions.cpp | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/asahi/compiler/agx_validate_ra.c b/src/asahi/compiler/agx_validate_ra.c index 272d4c40a7c0..4c60b86fe360 100644 --- a/src/asahi/compiler/agx_validate_ra.c +++ b/src/asahi/compiler/agx_validate_ra.c @@ -246,12 +246,12 @@ validate_block(agx_context *ctx, agx_block *block, struct regfile *blocks, unsigned idx = agx_predecessor_index(block, *pred); agx_index src = I->src[idx]; - assert(ra_class_for_index(src) == cls); if (!src.has_reg) { all_same = false; first = false; continue; } + assert(ra_class_for_index(src) == cls); struct regfile *pred_file = &blocks[(*pred)->index]; struct var_offset var = pred_file->r[cls][src.reg + offs]; diff --git a/src/asahi/compiler/test/test-native-form-regressions.cpp b/src/asahi/compiler/test/test-native-form-regressions.cpp index a761fede503c..b899787fe468 100644 --- a/src/asahi/compiler/test/test-native-form-regressions.cpp +++ b/src/asahi/compiler/test/test-native-form-regressions.cpp @@ -3425,6 +3425,40 @@ TEST(NativeForms, RegisterValidationTracksPhiCopies) } } +TEST(NativeForms, RegisterValidationAllowsNonRegSourceInSpilledPhi) +{ + EXPECT_EXIT({ + std::signal(SIGABRT, +[](int) { std::_Exit(77); }); + void *mem = ralloc_context(NULL); + agx_builder *b = agx_test_builder(mem); + agx_block *entry = agx_start_block(b->shader); + agx_block *left = agx_test_block(b->shader); + agx_block *right = agx_test_block(b->shader); + agx_block *join = agx_test_block(b->shader); + agx_block_add_successor(entry, left); + agx_block_add_successor(entry, right); + agx_block_add_successor(left, join); + agx_block_add_successor(right, join); + + b->cursor = agx_after_block(left); + agx_index spilled = validation_span_value(b, true, 80, AGX_SIZE_32, 1); + + b->cursor = agx_after_block(join); + agx_index dest = agx_temp(b->shader, AGX_SIZE_32); + dest.memory = true; + dest.has_reg = true; + dest.reg = 80; + agx_instr *phi = agx_phi_to(b, dest, 2); + phi->src[0] = spilled; + phi->src[1] = agx_immediate(0); + + agx_unit_test(b, dest); + agx_validate_ra(b->shader); + ralloc_free(mem); + std::_Exit(0); + }, ::testing::ExitedWithCode(0), ""); +} + TEST(NativeForms, RegisterValidationRetainsLoopHeaderRules) { for (bool invalid_livein : {false, true}) {