Skip to content

Commit 9833def

Browse files
vchuravygbaraldi
authored andcommitted
Only strip invariant.load from special pointers (#57386)
Other backends (in this case NVPTX) require that `invariant.load` metadata is maintained to generate non-coherent loads. Currently, we unconditionally strip that metadata from all loads, since our other uses of it may have become invalid. x-ref: llvm/llvm-project#112834 JuliaGPU/CUDA.jl#2531 --------- Co-authored-by: Gabriel Baraldi <baraldigabriel@gmail.com> (cherry picked from commit 29da86b)
1 parent 82b3c6d commit 9833def

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/llvm-late-gc-lowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,8 +2331,10 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
23312331
// strip all constant alias information, as it might depend on the gc having
23322332
// preserved a gc root, which stops being true after this pass (#32215)
23332333
// similar to RewriteStatepointsForGC::stripNonValidData, but less aggressive
2334-
if (I->getMetadata(LLVMContext::MD_invariant_load))
2335-
I->setMetadata(LLVMContext::MD_invariant_load, NULL);
2334+
if (auto *LI = dyn_cast<LoadInst>(I)){
2335+
if (isSpecialPtr(LI->getPointerOperand()->getType()) && LI->getMetadata(LLVMContext::MD_invariant_load))
2336+
LI->setMetadata(LLVMContext::MD_invariant_load, NULL);
2337+
}
23362338
if (MDNode *TBAA = I->getMetadata(LLVMContext::MD_tbaa)) {
23372339
if (TBAA->getNumOperands() == 4 && isTBAA(TBAA, {"jtbaa_const", "jtbaa_memoryptr", "jtbaa_memorylen", "tbaa_memoryown"})) {
23382340
MDNode *MutableTBAA = createMutableTBAAAccessTag(TBAA);

test/llvmpasses/late-lower-gc.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ top:
125125
ret void
126126
}
127127

128+
; Confirm that `invariant.load` on other loads survive
129+
define void @gc_keep_invariant(float addrspace(1)* %0) {
130+
top:
131+
; CHECK-LABEL: @gc_keep_invariant
132+
%pgcstack = call {}*** @julia.get_pgcstack()
133+
%1 = bitcast {}*** %pgcstack to {}**
134+
%current_task = getelementptr inbounds {}*, {}** %1, i64 -12
135+
136+
; CHECK: %current_task = getelementptr inbounds ptr, ptr %1, i64 -12
137+
%2 = load float, ptr addrspace(1) %0, align 4, !invariant.load !1
138+
; CHECK-NEXT: %2 = load float, ptr addrspace(1) %0, align 4, !invariant.load
139+
ret void
140+
}
141+
128142
define i32 @callee_root({} addrspace(10)* %v0, {} addrspace(10)* %v1) {
129143
top:
130144
; CHECK-LABEL: @callee_root

0 commit comments

Comments
 (0)