diff options
author | Chen Li <meloli87@gmail.com> | 2015-09-10 22:35:41 +0000 |
---|---|---|
committer | Chen Li <meloli87@gmail.com> | 2015-09-10 22:35:41 +0000 |
commit | 55a7e0fc54a10543692af9c5c386989956142871 (patch) | |
tree | ab4688773c96066e930a6b780ef036fbd572368b | |
parent | 4d0f917f947f96d50ba4841d76b22a3d797889f9 (diff) |
[InstCombineCalls] Use isKnownNonNullAt() to check nullness of gc.relocate return value
Summary: This patch replaces isKnownNonNull() with isKnownNonNullAt() when checking nullness of gc.relocate return value. In this way it can handle cases where the relocated value does not have nonnull attribute but has a dominating null check from the CFG.
Reviewers: reames
Subscribers: llvm-commits, sanjoy
Differential Revision: http://reviews.llvm.org/D12772
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247353 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 | ||||
-rw-r--r-- | test/Transforms/InstCombine/gc.relocate.ll | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 1b9abfdacbf..cc7d4be7a78 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1367,7 +1367,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } // isKnownNonNull -> nonnull attribute - if (isKnownNonNull(DerivedPtr)) + if (isKnownNonNullAt(DerivedPtr, II, DT, TLI)) II->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull); // isDereferenceablePointer -> deref attribute diff --git a/test/Transforms/InstCombine/gc.relocate.ll b/test/Transforms/InstCombine/gc.relocate.ll index a51aac10eb5..6003bff1527 100644 --- a/test/Transforms/InstCombine/gc.relocate.ll +++ b/test/Transforms/InstCombine/gc.relocate.ll @@ -19,3 +19,34 @@ entry: %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) ret i32 addrspace(1)* %relocate } + +define i32 @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" { +; Checks that a nonnull pointer +; CHECK-LABEL: @explicit_nonnull +; CHECK: ret i32 1 +entry: + %load = load i32, i32 addrspace(1)* %dparam + %tok = tail 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 addrspace(1)* %dparam) + %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) + %cmp = icmp eq i32 addrspace(1)* %relocate, null + %ret_val = select i1 %cmp, i32 0, i32 1 + ret i32 %ret_val +} + +define i32 @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" { +; Checks that a nonnull pointer +; CHECK-LABEL: @implicit_nonnull +; CHECK: ret i32 1 +entry: + %cond = icmp eq i32 addrspace(1)* %dparam, null + br i1 %cond, label %no_gc, label %gc +gc: + %load = load i32, i32 addrspace(1)* %dparam + %tok = tail 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 addrspace(1)* %dparam) + %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7) + %cmp = icmp eq i32 addrspace(1)* %relocate, null + %ret_val = select i1 %cmp, i32 0, i32 1 + ret i32 %ret_val +no_gc: + unreachable +} |