[PATCH] D12932: [LazyValueInfo] Report nonnull range for nonnull pointers

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 06:20:16 PDT 2015


igor-laevsky created this revision.
igor-laevsky added a reviewer: reames.
igor-laevsky added a subscriber: llvm-commits.
igor-laevsky set the repository for this revision to rL LLVM.

Currently LazyValueInfo will report only alloca's as having nonnull range. For loads with !nonnull metadata it will bailout with no additional information. Same is true for calls returning nonnull pointers.

This change extends LazyValueInfo to handle this additional nonnull instructions.



Repository:
  rL LLVM

http://reviews.llvm.org/D12932

Files:
  lib/Analysis/LazyValueInfo.cpp
  test/Transforms/CorrelatedValuePropagation/non-null.ll

Index: test/Transforms/CorrelatedValuePropagation/non-null.ll
===================================================================
--- test/Transforms/CorrelatedValuePropagation/non-null.ll
+++ test/Transforms/CorrelatedValuePropagation/non-null.ll
@@ -140,3 +140,24 @@
   ; CHECK: call void @test11_helper(i8* nonnull %merged_arg)
   ret void
 }
+
+declare void @test12_helper(i8* %arg)
+define void @test12(i8* %arg1, i8** %arg2) {
+; CHECK-LABEL: @test12
+entry:
+  %is_null = icmp eq i8* %arg1, null
+  br i1 %is_null, label %null, label %non_null
+
+non_null:
+  br label %merge
+
+null:
+  %another_arg = load i8*, i8** %arg2, !nonnull !{}
+  br label %merge
+
+merge:
+  %merged_arg = phi i8* [%another_arg, %null], [%arg1, %non_null]
+  call void @test12_helper(i8* %merged_arg)
+  ; CHECK: call void @test12_helper(i8* nonnull %merged_arg)
+  ret void
+}
Index: lib/Analysis/LazyValueInfo.cpp
===================================================================
--- lib/Analysis/LazyValueInfo.cpp
+++ lib/Analysis/LazyValueInfo.cpp
@@ -531,8 +531,11 @@
     return true;
   }
 
-  if (AllocaInst *AI = dyn_cast<AllocaInst>(BBI)) {
-    Res = LVILatticeVal::getNot(ConstantPointerNull::get(AI->getType()));
+  // If this value is a nonnull pointer, record it's range and bailout.
+  if (BBI->getType()->isPointerTy() &&
+      isKnownNonNull(BBI)) {
+    Res = LVILatticeVal::getNot(
+        ConstantPointerNull::get(cast<PointerType>(BBI->getType())));
     insertResult(Val, BB, Res);
     return true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12932.34984.patch
Type: text/x-patch
Size: 1517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150917/49a7ac2a/attachment.bin>


More information about the llvm-commits mailing list