[InstCombineCalls] Use isKnownNonNullAt() to check nullness of passing arguments...
authorChen Li <meloli87@gmail.com>
Thu, 10 Sep 2015 23:04:49 +0000 (23:04 +0000)
committerChen Li <meloli87@gmail.com>
Thu, 10 Sep 2015 23:04:49 +0000 (23:04 +0000)
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
test/Transforms/InstCombine/call_nonnull_arg.ll [new file with mode: 0644]

index cc7d4be7a78063cbfab384f282609aa655bc307c..900953af6c600765d442d4e54f716e921cf54d32 100644 (file)
@@ -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 (file)
index 0000000..cac53d3
--- /dev/null
@@ -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
+}