Conversation
LLVM can merge the loads from several relocation slots into a single load from a phi or select of the slots' addresses, e.g. when a boxed value is compared against the singletons it may be. The :table lowering only redirected direct loads of a slot, so such a slot kept a use and compilation failed with "still has uses after redirection". Rebuild those phis and selects over the slots' table offsets instead, and load the word at the resulting offset. Merging a slot with any other address, or using a merged address for anything but loading its word, still errors. Libjulia globals can be merged the same way, e.g. jl_nothing with the slots of other singletons. Only their direct loads were relocated, leaving the phi referencing the global itself. As such a phi is only ever loaded from, give it the address of the global's slot, which holds the same word, and report merged loads that cannot be redirected as unresolved. Fixes #959.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #960 +/- ##
==========================================
- Coverage 86.59% 81.01% -5.59%
==========================================
Files 29 29
Lines 5760 6277 +517
==========================================
+ Hits 4988 5085 +97
- Misses 772 1192 +420 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Redirect both direct and merged cglobal addresses to their word slots. This keeps pointer loads intact instead of rebuilding them as integer loads followed by inttoptr, which can miscompile mixed singleton comparisons on Metal.
Use replace_global_with_local! and LLVM address-space inference instead of rebuilding pointer PHIs and selects as an offset graph. Keep the word-load checks, cap alignment at the table word size, and discard session-specific load names. Expand constant users before choosing insertion points so later substitutions cannot introduce uses before their definitions.
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.
LLVM can merge singleton-address loads into a load from a
phiorselectof relocation slot addresses. Metal's table lowering only handled direct loads, so kernels comparing a boxed value against several singletons failed with “Relocation slot … still has uses after redirection”.Replace each slot address with its indexed address in the relocation table, using
replace_global_with_local!, and let LLVM's address-space inference propagate the table's address space through the existing PHIs, selects and casts. This also handles loop-carried addresses without rebuilding them as an integer-offset graph. Expand constant users before choosing entry insertion points, retain the word-load restrictions, and adjust alignment and load names for packed, reproducible tables.Redirect cglobal addresses such as
jl_nothingto relocation slots in the same way, preserving the original loads. Keeping their pointer load types matters on Metal: mixing preserved pointer loads with cglobal loads rebuilt as integers followed byinttoptrgave incorrect singleton comparisons on the M1. Unsupported cglobal loads remain diagnosed.Validation:
jl_nothing; tests also cover alignment, preserved cglobal load types, reproducibility, and rejected non-word loads, writes and unrelated addresses.nothingvariant and a loop variant return the expected results for inputs 1–7 repeated over 896 elements, across three launches each. Validated from a fresh process using the final source.Fixes #959