Repository navigation
GCN: fold null checks of stack objects - #1000
Merged
Merged
Conversation
Julia 1.10 represents phis of immutables kept in memory as phis of pointers, with null for undefined incoming values, and guards their loads with a null check. LLVM folds these checks once the phi reduces to an alloca, except in address spaces where null is a valid address, like AMDGPU's private one. The check then survives, and holds for the stack object at private address 0, so the value reads as undef. This broke AcceleratedKernels' reductions with 16-byte accumulators on Julia 1.10. Fold the checks before and after optimization. That also lets SROA promote the stack slot, so these kernels no longer use scratch memory.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1000 +/- ##
==========================================
+ Coverage 81.74% 89.46% +7.71%
==========================================
Files 31 31
Lines 6854 6883 +29
==========================================
+ Hits 5603 6158 +555
+ Misses 1251 725 -526 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Julia 1.10 represents phis of immutables kept in memory as phis of pointers, with null for undefined incoming values, and guards their loads with
ptr == null ? undef : load(ptr). LLVM folds those checks once the phi reduces to an alloca, but not in address spaces where null is a valid address, like AMDGPU's private one. The check then survives, and on AMDGPU it holds for the stack object at private address 0 (s_cmp_eq_u32 0, 0in the ISA), so the value reads asundef.This broke AcceleratedKernels' reductions with 16-byte accumulators on Julia 1.10 (ComplexF64 / Complex{Int64} sums, and reductions with operators without a neutral element), which return garbage in AMDGPU.jl's GPUArrays 12 port (JuliaGPU/AMDGPU.jl#1145). Julia 1.11+ doesn't emit these checks.
This PR folds the comparisons in the GCN target, before optimization and again after. Folding them also lets SROA promote the stack slot, so the affected kernels no longer use scratch memory (24 bytes before, 0 after). The new test checks the IR of a kernel shaped like AK's reduction. On Julia 1.10 it has two such checks without the fold. With the fold, AMDGPU's failing GPUArrays testsets pass on Julia 1.10 (gfx1036).
Bumps the version to 2.13.1.
The second commit fixes the GCN
atomic validationtest, broken on main since #983:llvm_datalayoutnow returns a string for the external back-end, and the test tried to@disposeit.