Skip to content

Commit

Permalink
Don't ignore memcpy in GC root placement
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Sep 2, 2017
1 parent 92ff781 commit 3c68dcd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,16 @@ State LateLowerGCFrame::LocalScan(Function &F) {
Instruction &I = *it;
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
if (isa<IntrinsicInst>(CI)) {
// Intrinsics are never GC uses/defs
continue;
// Most intrinsics are not gc uses/defs, however some have
// memory operands and could thus be GC uses. To be conservative,
// we only skip processing for those that we know we emit often
// and cannot possibly be GC uses.
IntrinsicInst *II = cast<IntrinsicInst>(CI);
if (isa<DbgInfoIntrinsic>(CI) ||
II->getIntrinsicID() == Intrinsic::lifetime_start ||
II->getIntrinsicID() == Intrinsic::lifetime_end) {
continue;
}
}
MaybeNoteDef(S, BBS, CI, BBS.Safepoints);
NoteOperandUses(S, BBS, I, BBS.UpExposedUses);
Expand All @@ -743,6 +751,10 @@ State LateLowerGCFrame::LocalScan(Function &F) {
if (CI->canReturnTwice()) {
S.ReturnsTwice.push_back(CI);
}
if (isa<IntrinsicInst>(CI)) {
// Intrinsics are never safepoints.
continue;
}
if (auto callee = CI->getCalledFunction()) {
// Known functions emitted in codegen that are not safepoints
if (callee == pointer_from_objref_func || callee->getName() == "memcmp") {
Expand Down
18 changes: 17 additions & 1 deletion test/llvmpasses/gcroots.ll
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ define %jl_value_t addrspace(10)* @no_redundant_rerooting(i64 %a, i1 %cond) {
top:
%ptls = call %jl_value_t*** @jl_get_ptls_states()
%aboxed = call %jl_value_t addrspace(10)* @jl_box_int64(i64 signext %a)
; CHECK: store %jl_value_t addrspace(10)* %aboxed
; CHECK: store %jl_value_t addrspace(10)* %aboxed
; CHECK-NEXT: call void @jl_safepoint()
call void @jl_safepoint()
br i1 %cond, label %blocka, label %blockb
Expand All @@ -207,3 +207,19 @@ blockb:
call void @jl_safepoint()
ret %jl_value_t addrspace(10)* %aboxed
}

declare void @llvm.memcpy.p064.p10i8.i64(i64*, i8 addrspace(10)*, i64, i32, i1)

define void @memcpy_use(i64 %a, i64 *%aptr) {
; CHECK-LABEL: @memcpy_use
; CHECK: %gcframe = alloca %jl_value_t addrspace(10)*, i32 3
top:
%ptls = call %jl_value_t*** @jl_get_ptls_states()
%aboxed = call %jl_value_t addrspace(10)* @jl_box_int64(i64 signext %a)
; CHECK: store %jl_value_t addrspace(10)* %aboxed
call void @jl_safepoint()
%acast = bitcast %jl_value_t addrspace(10)* %aboxed to i8 addrspace(10)*
call void @llvm.memcpy.p064.p10i8.i64(i64* %aptr, i8 addrspace(10)* %acast, i64 8, i32 1, i1 false)
ret void
}

0 comments on commit 3c68dcd

Please sign in to comment.