[PATCH] D12772: [InstCombineCalls] Use isKnownNonNullAt() to check nullness of gc.relocate return value

Chen Li via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 13:48:26 PDT 2015


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

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.

http://reviews.llvm.org/D12772

Files:
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/gc.relocate.ll

Index: test/Transforms/InstCombine/gc.relocate.ll
===================================================================
--- test/Transforms/InstCombine/gc.relocate.ll
+++ test/Transforms/InstCombine/gc.relocate.ll
@@ -19,3 +19,30 @@
     %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok,  i32 7, i32 7)
     ret i32 addrspace(1)* %relocate
 }
+
+define i32 addrspace(1)* @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" {
+; Checks that a nonnull pointer
+; CHECK-LABEL: @explicit_nonnull
+; CHECK: call nonnull
+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)
+    ret i32 addrspace(1)* %relocate
+}
+
+define i32 addrspace(1)* @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" {
+; Checks that a nonnull pointer
+; CHECK-LABEL: @implicit_nonnull
+; CHECK: call nonnull
+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)
+    ret i32 addrspace(1)* %relocate
+no_gc:
+    ret i32 addrspace(1)* %dparam
+}
\ No newline at end of file
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1367,7 +1367,7 @@
     }
 
     // isKnownNonNull -> nonnull attribute
-    if (isKnownNonNull(DerivedPtr))
+    if (isKnownNonNullAt(DerivedPtr, II, DT, TLI))
       II->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull);
 
     // isDereferenceablePointer -> deref attribute


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12772.34485.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150910/79d09d4a/attachment.bin>


More information about the llvm-commits mailing list