summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Li <meloli87@gmail.com>2015-09-10 23:04:49 +0000
committerChen Li <meloli87@gmail.com>2015-09-10 23:04:49 +0000
commita29c612ddd84e91718fbb8915a25a50f9c4a3f88 (patch)
tree4e142856dd0eb2782a8ab9953003acd93ef4a8a4
parentdd34a4d3c58bbea8f64e8b8b80801d830608b33f (diff)
downloadbcm5719-llvm-a29c612ddd84e91718fbb8915a25a50f9c4a3f88.tar.gz
bcm5719-llvm-a29c612ddd84e91718fbb8915a25a50f9c4a3f88.zip
[InstCombineCalls] Use isKnownNonNullAt() to check nullness of passing arguments at callsite
Summary: This patch replaces isKnownNonNull() with isKnownNonNullAt() when checking nullness of passing arguments at callsite. In this way it can handle cases where the argument does not have nonnull attribute but has a dominating null check from the CFG. Reviewers: reames Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12779 llvm-svn: 247356
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp2
-rw-r--r--llvm/test/Transforms/InstCombine/call_nonnull_arg.ll17
2 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index cc7d4be7a78..900953af6c6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1537,7 +1537,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
unsigned ArgNo = 0;
for (Value *V : CS.args()) {
if (!CS.paramHasAttr(ArgNo+1, Attribute::NonNull) &&
- isKnownNonNull(V)) {
+ isKnownNonNullAt(V, CS.getInstruction(), DT, TLI)) {
AttributeSet AS = CS.getAttributes();
AS = AS.addAttribute(CS.getInstruction()->getContext(), ArgNo+1,
Attribute::NonNull);
diff --git a/llvm/test/Transforms/InstCombine/call_nonnull_arg.ll b/llvm/test/Transforms/InstCombine/call_nonnull_arg.ll
new file mode 100644
index 00000000000..cac53d3d47a
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/call_nonnull_arg.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; InstCombine should mark null-checked argument as nonnull at callsite
+declare void @dummy(i32*)
+
+define void @test(i32* %a) {
+; CHECK-LABEL: @test
+; CHECK: call void @dummy(i32* nonnull %a)
+entry:
+ %cond = icmp eq i32* %a, null
+ br i1 %cond, label %is_null, label %not_null
+not_null:
+ call void @dummy(i32* %a)
+ ret void
+is_null:
+ unreachable
+}
OpenPOWER on IntegriCloud