Fix sret alloca alignment to match callee's preferred type alignment#61192
Merged
Fix sret alloca alignment to match callee's preferred type alignment#61192
Conversation
vtjnash
reviewed
Feb 27, 2026
a908e3c to
2464148
Compare
Member
|
LGTM |
topolarity
reviewed
Mar 3, 2026
topolarity
reviewed
Mar 3, 2026
The sret parameter's alignment attribute was set to LLVM's preferred type alignment (getPrefTypeAlign), which can exceed julia_alignment. This caused misaligned memory accesses on strict-alignment targets like NVPTX, since the caller's alloca uses julia_alignment. Fix by setting the sret alignment to julia_alignment and not overriding it in the function definition, so that caller and callee agree on the same alignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
vtjnash
approved these changes
Mar 3, 2026
maleadt
added a commit
that referenced
this pull request
Mar 6, 2026
The sret parameter's alignment attribute was set to LLVM's preferred type alignment (getPrefTypeAlign), which can exceed julia_alignment. This caused misaligned memory accesses on strict-alignment targets like NVPTX, since the caller's alloca uses julia_alignment. Fix by setting the sret alignment to julia_alignment and not overriding it in the function definition, so that caller and callee agree on the same alignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
maleadt
added a commit
that referenced
this pull request
Mar 6, 2026
The sret parameter's alignment attribute was set to LLVM's preferred type alignment (getPrefTypeAlign), which can exceed julia_alignment. This caused misaligned memory accesses on strict-alignment targets like NVPTX, since the caller's alloca uses julia_alignment. Fix by setting the sret alignment to julia_alignment and not overriding it in the function definition, so that caller and callee agree on the same alignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
The caller's sret alloca used julia_alignment (union_align) which can be smaller than the LLVM preferred type alignment that the callee uses for its loads/stores. For example, a struct of floats gets julia_alignment=4 but the callee uses DL.getPrefTypeAlign()=8, generating 8-byte-aligned memcpy operations. On strict-alignment targets (NVPTX), the resulting misaligned access causes CUDA_ERROR_MISALIGNED_ADDRESS.
Fix by computing the sret type's preferred alignment from the callee's StructRet attribute and taking the max with union_align, matching the alignment the callee computes for its sret parameter.
Fixes JuliaGPU/CUDA.jl#3034
Regression introduced in 1.12 by #55730