From e78962ca4aa09a84884a58bb8cc836c4c6db9ab2 Mon Sep 17 00:00:00 2001 From: Igor Laevsky Date: Tue, 3 Nov 2015 18:37:40 +0000 Subject: [PATCH] [CodegenPrepare] Do not rematerialize gc.relocates across different basic blocks Differential Revision: http://reviews.llvm.org/D14258 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251957 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPrepare.cpp | 8 ++++ .../CodeGenPrepare/statepoint-relocate.ll | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index 76ca1350b41..de5c68f7767 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -589,6 +589,14 @@ simplifyRelocatesOffABase(IntrinsicInst *RelocatedBase, continue; } + if (RelocatedBase->getParent() != ToReplace->getParent()) { + // Base and derived relocates are in different basic blocks. + // In this case transform is only valid when base dominates derived + // relocate. However it would be too expensive to check dominance + // for each such relocate, so we skip the whole transformation. + continue; + } + Value *Base = ThisRelocate.getBasePtr(); auto Derived = dyn_cast(ThisRelocate.getDerivedPtr()); if (!Derived || Derived->getPointerOperand() != Base) diff --git a/test/Transforms/CodeGenPrepare/statepoint-relocate.ll b/test/Transforms/CodeGenPrepare/statepoint-relocate.ll index b6898b37311..93e17582813 100644 --- a/test/Transforms/CodeGenPrepare/statepoint-relocate.ll +++ b/test/Transforms/CodeGenPrepare/statepoint-relocate.ll @@ -83,6 +83,45 @@ entry: ret i32 %ret } +define i32 @test_sor_basic_wrong_order(i32* %base) gc "statepoint-example" { +; CHECK-LABEL: @test_sor_basic_wrong_order +; Here we have base relocate inserted after derived. Make sure that we don't +; produce uses of the relocated base pointer before it's definition. +entry: + %ptr = getelementptr i32, i32* %base, i32 15 + ; CHECK: getelementptr i32, i32* %base, i32 15 + %tok = call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32* %base, i32* %ptr) + %ptr-new = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 8) + %base-new = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 7) + ; CHECK: %base-new = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 7) + ; CHECK-NEXT: getelementptr i32, i32* %base-new, i32 15 + %ret = load i32, i32* %ptr-new + ret i32 %ret +} + +define i32 @test_sor_noop_cross_bb(i1 %external-cond, i32* %base) gc "statepoint-example" { +; CHECK-LABEL: @test_sor_noop_cross_bb +; Here base relocate doesn't dominate derived relocate. Make sure that we don't +; produce undefined use of the relocated base pointer. +entry: + %ptr = getelementptr i32, i32* %base, i32 15 + ; CHECK: getelementptr i32, i32* %base, i32 15 + %tok = call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32* %base, i32* %ptr) + br i1 %external-cond, label %left, label %right + +left: + %ptr-new = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 8) + ; CHECK: call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 8) + %ret-new = load i32, i32* %ptr-new + ret i32 %ret-new + +right: + %ptr-base = call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 7) + ; CHECK: call i32* @llvm.experimental.gc.relocate.p0i32(i32 %tok, i32 7, i32 7) + %ret-base = load i32, i32* %ptr-base + ret i32 %ret-base +} + declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...) declare i32* @llvm.experimental.gc.relocate.p0i32(i32, i32, i32) declare [3 x i32]* @llvm.experimental.gc.relocate.p0a3i32(i32, i32, i32) -- 2.34.1