From 337cd218ef3635b2105be7578640ed16fe0a9a38 Mon Sep 17 00:00:00 2001 From: Chen Li Date: Thu, 10 Sep 2015 23:04:49 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247356 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +- test/Transforms/InstCombine/call_nonnull_arg.ll | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/Transforms/InstCombine/call_nonnull_arg.ll diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index cc7d4be7a78..900953af6c6 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/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/test/Transforms/InstCombine/call_nonnull_arg.ll b/test/Transforms/InstCombine/call_nonnull_arg.ll new file mode 100644 index 00000000000..cac53d3d47a --- /dev/null +++ b/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 +} -- 2.34.1