Skip to content

Commit 29da86b

Browse files
vchuravygbaraldi
andauthored
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>
1 parent d43a5ad commit 29da86b

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
@@ -2011,8 +2011,10 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
20112011
// strip all constant alias information, as it might depend on the gc having
20122012
// preserved a gc root, which stops being true after this pass (#32215)
20132013
// similar to RewriteStatepointsForGC::stripNonValidData, but less aggressive
2014-
if (I->getMetadata(LLVMContext::MD_invariant_load))
2015-
I->setMetadata(LLVMContext::MD_invariant_load, NULL);
2014+
if (auto *LI = dyn_cast<LoadInst>(I)){
2015+
if (isSpecialPtr(LI->getPointerOperand()->getType()) && LI->getMetadata(LLVMContext::MD_invariant_load))
2016+
LI->setMetadata(LLVMContext::MD_invariant_load, NULL);
2017+
}
20162018
if (MDNode *TBAA = I->getMetadata(LLVMContext::MD_tbaa)) {
20172019
if (TBAA->getNumOperands() == 4 && isTBAA(TBAA, {"jtbaa_const", "jtbaa_memoryptr", "jtbaa_memorylen", "tbaa_memoryown"})) {
20182020
MDNode *MutableTBAA = createMutableTBAAAccessTag(TBAA);

test/llvmpasses/late-lower-gc.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ top:
9090
ret void
9191
}
9292

93+
; Confirm that `invariant.load` on other loads survive
94+
define void @gc_keep_invariant(float addrspace(1)* %0) {
95+
top:
96+
; CHECK-LABEL: @gc_keep_invariant
97+
%pgcstack = call {}*** @julia.get_pgcstack()
98+
%1 = bitcast {}*** %pgcstack to {}**
99+
%current_task = getelementptr inbounds {}*, {}** %1, i64 -12
100+
101+
; CHECK: %current_task = getelementptr inbounds ptr, ptr %1, i64 -12
102+
%2 = load float, ptr addrspace(1) %0, align 4, !invariant.load !1
103+
; CHECK-NEXT: %2 = load float, ptr addrspace(1) %0, align 4, !invariant.load
104+
ret void
105+
}
106+
93107
define i32 @callee_root({} addrspace(10)* %v0, {} addrspace(10)* %v1) {
94108
top:
95109
; CHECK-LABEL: @callee_root

0 commit comments

Comments
 (0)