[libspirv] Clone remangled functions on name clash (private default AS) #20889
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.
When the target’s default address space is private (e.g., SPIR), simultaneous pointer address space remangling and long -> long long remangling can cause clone name collisions, preventing the remangled function from being cloned.
Example:
_Z1fPm -> remangled to _Z1fPU3AS0y; remangler clones back to _Z1fPm to preserve the original.
Later, _Z1fPU3AS4m -> remangled to _Z1fPy; we need to clone _Z1fPy to _Z1fPm, but _Z1fPm already exists.
Fix:
Append a temporary suffix to avoid clashes (e.g., _Z1fPm$TmpSuffix). Remove the suffix in post-processing, replacing the old _Z1fPm (clone of _Z1fPU3AS0y) with the new remangled implementation.
llvm-diff shows no change for targets whose default AS isn't private: remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc and remangled-l64-unsigned_char.libspirv-amdgcn-amd-amdhsa.bc.