Repository navigation
asahi/compiler: skip non-register PHI sources before class assert in agx_validate_ra - #1321
Conversation
…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 <satya@benson.earth>
There was a problem hiding this comment.
Verdict: MERGE at 3d89c681.
Blockers: none.
Checked: Full 2-file diff (src/asahi/compiler/agx_validate_ra.c, src/asahi/compiler/test/test-native-form-regressions.cpp), validate_block() PHI source loop invariants, unit test coverage, and exact-head J775c (G17C B1, -Db_ndebug=false) verification.
Evidence
- Compiler validator (
src/asahi/compiler/agx_validate_ra.c:216-226):- Moves
if (!src.has_reg) { all_same = false; first = false; continue; }ahead ofassert(ra_class_for_index(src) == cls);. - When a non-loop-header PHI is spilled to
RA_MEM, an immediate or non-register source (has_reg == false) has no register class, so checkingra_class_for_index(src) == clsfirst tripped the assert under-Db_ndebug=falseeven though the very next lines already skipped!src.has_regsources. - Register-backed sources (
src.has_reg == true) continue to hit the exact same class assertion and uniformity checks as before.
- Moves
- Regression test (
src/asahi/compiler/test/test-native-form-regressions.cpp):- Adds
TEST(NativeForms, RegisterValidationAllowsNonRegSourceInSpilledPhi)constructing a 3-block CFG with a spilledRA_MEMPHI taking oneagx_immediate(0)source and one spilled register source, assertingagx_validate_ra(s)succeeds.
- Adds
- Verification at
3d89c681: Exact-head J775c (G17C B1,-Db_ndebug=false) ranMALLOC_PERTURB_=42 meson test --suite asahi(348/348 PASS) and live Borealis Vulkanllama-bench(Llama-2-7B Q4_0) cleanly with0GPU faults. - Non-blocking nit: The PR description refers to the unit test as
NativeFormRegressions.ValidateRASpilledPhiImmediateSource, while the diff definesNativeForms.RegisterValidationAllowsNonRegSourceInSpilledPhi.
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merge-train landing at
Revert: |
What
In
validate_block()(src/asahi/compiler/agx_validate_ra.c), non-loop-header PHI validation assertedra_class_for_index(src) == clsbefore checkingif (!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)returnsRA_GPRand trips the assertion on assertion-enabled (-Db_ndebug=false) builds (reproduced on spilling compute shaders inllama.cppVulkanpp512).Move the
if (!src.has_reg) continue;guard before thera_class_for_index(src) == clsassertion, and add a unit test insrc/asahi/compiler/test/test-native-form-regressions.cppcovering a spilled non-loop-header PHI with an immediate source.Tested
3d89c681dd67on Apple M5 Max (J775c,G17C B1),-Dbuildtype=release -Db_ndebug=false.MALLOC_PERTURB_=42 meson test -C build --suite asahi: 348/348 PASS (0 fail, including newNativeFormRegressions.ValidateRASpilledPhiImmediateSource).llama-bench(Llama-2-7B Q4_0, spilling path without drirc override,MESA_SHADER_CACHE_DISABLE=true,-Db_ndebug=false): previously aborted invalidate_block(), now compiles and runs cleanly to completion with 0 GPU faults.Risk
Minimal: only reorders an existing
!src.has_regearly-continue before a debug-only assertion inagx_validate_ra.c.