From: Manuel Jacob Date: Tue, 22 Dec 2015 16:50:44 +0000 (+0000) Subject: [RS4GC] Fix crash in the case that a live variable has a constant base. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=f8bc6b53de9295bb11aa334888421269bda8c7ca [RS4GC] Fix crash in the case that a live variable has a constant base. Summary: Previously, RS4GC crashed in CreateGCRelocates() because it assumed that every base is also in the array of live variables, which isn't true if a live variable has a constant base. This change fixes the crash by making sure CreateGCRelocates() won't try to relocate a live variable with a constant base. This would be unnecessary anyway because anything with a constant base won't move. Reviewers: reames Subscribers: llvm-commits, sanjoy Differential Revision: http://reviews.llvm.org/D15556 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256252 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index 049a7fc5459..083aec33dc9 100644 --- a/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -2387,6 +2387,19 @@ static bool insertParsePoints(Function &F, DominatorTree &DT, } } + // It is possible that non-constant live variables have a constant base. For + // example, a GEP with a variable offset from a global. In this case we can + // remove it from the liveset. We already don't add constants to the liveset + // because we assume they won't move at runtime and the GC doesn't need to be + // informed about them. The same reasoning applies if the base is constant. + // Note that the relocation placement code relies on this filtering for + // correctness as it expects the base to be in the liveset, which isn't true + // if the base is constant. + for (auto &Info : Records) + for (auto &BasePair : Info.PointerToBase) + if (isa(BasePair.second)) + Info.LiveSet.erase(BasePair.first); + for (CallInst *CI : Holders) CI->eraseFromParent(); diff --git a/test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll b/test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll new file mode 100644 index 00000000000..d4425a77a53 --- /dev/null +++ b/test/Transforms/RewriteStatepointsForGC/base-pointers-12.ll @@ -0,0 +1,20 @@ +; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s + +; CHECK: derived %select base %global + +@global = external addrspace(1) global i8 + +define i8 @test(i1 %cond) gc "statepoint-example" { + %derived1 = getelementptr i8, i8 addrspace(1)* @global, i64 1 + %derived2 = getelementptr i8, i8 addrspace(1)* @global, i64 2 + %select = select i1 %cond, i8 addrspace(1)* %derived1, i8 addrspace(1)* %derived2 + %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @extern, i32 0, i32 0, i32 0, i32 0) +; CHECK-NOT: relocate +; CHECK: %load = load i8, i8 addrspace(1)* %select + %load = load i8, i8 addrspace(1)* %select + ret i8 %load +} + +declare void @extern() gc "statepoint-example" + +declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) diff --git a/test/Transforms/RewriteStatepointsForGC/base-pointers-13.ll b/test/Transforms/RewriteStatepointsForGC/base-pointers-13.ll new file mode 100644 index 00000000000..9c16eb236f2 --- /dev/null +++ b/test/Transforms/RewriteStatepointsForGC/base-pointers-13.ll @@ -0,0 +1,19 @@ +; RUN: opt %s -rewrite-statepoints-for-gc -spp-print-base-pointers -S 2>&1 | FileCheck %s + +; CHECK: derived %derived base %global + +@global = external addrspace(1) global i8 + +define i8 @test(i64 %offset) gc "statepoint-example" { + %derived = getelementptr i8, i8 addrspace(1)* @global, i64 %offset + %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @extern, i32 0, i32 0, i32 0, i32 0) +; CHECK-NOT: relocate +; CHECK-NOT: remat +; CHECK: %load = load i8, i8 addrspace(1)* %derived + %load = load i8, i8 addrspace(1)* %derived + ret i8 %load +} + +declare void @extern() gc "statepoint-example" + +declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)