[PATCH] D12779: [InstCombineCalls] Use isKnownNonNullAt() to check nullness of passing arguments at callsite

Chen Li via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 15:42:35 PDT 2015


chenli created this revision.
chenli added a reviewer: reames.
chenli added a subscriber: llvm-commits.

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.

http://reviews.llvm.org/D12779

Files:
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/call_nonnull_arg.ll

Index: test/Transforms/InstCombine/call_nonnull_arg.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1537,7 +1537,7 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12779.34502.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150910/3b386634/attachment.bin>


More information about the llvm-commits mailing list