Skip to content

Commit e53c46a

Browse files
authored
[Statepoint] Treat result of atomicrmw xchg as a base pointer (#97280)
Atomic RMW Xchg wasn't handled before when searching for known base pointers in the IR.
1 parent e4d57d6 commit e53c46a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,15 @@ static Value *findBaseDefiningValue(Value *I, DefiningValueMapTy &Cache,
577577
return I;
578578
}
579579

580-
assert(!isa<AtomicRMWInst>(I) && "Xchg handled above, all others are "
581-
"binary ops which don't apply to pointers");
580+
if (auto *RMWI = dyn_cast<AtomicRMWInst>(I)) {
581+
assert(RMWI->getOperation() == AtomicRMWInst::Xchg &&
582+
"Only Xchg is allowed for pointer values");
583+
// A RMW Xchg is a combined atomic load and store, so we can treat the
584+
// loaded value as a base pointer.
585+
Cache[I] = I;
586+
setKnownBase(I, /* IsKnownBase */ true, KnownBases);
587+
return I;
588+
}
582589

583590
// The aggregate ops. Aggregates can either be in the heap or on the
584591
// stack, but in either case, this is simply a field load. As a result,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
2+
3+
define ptr addrspace(1) @test(ptr %a, ptr addrspace(1) %b) gc "statepoint-example" {
4+
; CHECK-LABEL: @test
5+
; CHECK-NEXT: [[RES:%.*]] = atomicrmw xchg ptr %a, ptr addrspace(1) %b seq_cst
6+
; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[RES]]) ]
7+
; CHECK-NEXT: [[RES_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
8+
; CHECK-NEXT: ret ptr addrspace(1) [[RES_RELOCATED]]
9+
%res = atomicrmw xchg ptr %a, ptr addrspace(1) %b seq_cst
10+
call void @foo()
11+
ret ptr addrspace(1) %res
12+
}
13+
14+
declare void @foo()

0 commit comments

Comments
 (0)