Skip to content

Commit 3e597e4

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 cfb43c4 commit 3e597e4

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
@@ -2305,8 +2305,10 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
23052305
// strip all constant alias information, as it might depend on the gc having
23062306
// preserved a gc root, which stops being true after this pass (#32215)
23072307
// similar to RewriteStatepointsForGC::stripNonValidData, but less aggressive
2308-
if (I->getMetadata(LLVMContext::MD_invariant_load))
2309-
I->setMetadata(LLVMContext::MD_invariant_load, NULL);
2308+
if (auto *LI = dyn_cast<LoadInst>(I)){
2309+
if (isSpecialPtr(LI->getPointerOperand()->getType()) && LI->getMetadata(LLVMContext::MD_invariant_load))
2310+
LI->setMetadata(LLVMContext::MD_invariant_load, NULL);
2311+
}
23102312
if (MDNode *TBAA = I->getMetadata(LLVMContext::MD_tbaa)) {
23112313
if (TBAA->getNumOperands() == 4 && isTBAA(TBAA, {"jtbaa_const"})) {
23122314
MDNode *MutableTBAA = createMutableTBAAAccessTag(TBAA);

test/llvmpasses/late-lower-gc.ll

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

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

0 commit comments

Comments
 (0)