[llvm] r247985 - [LazyValueInfo] Report nonnull range for nonnull pointers

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 06:01:48 PDT 2015


Author: igor.laevsky
Date: Fri Sep 18 08:01:48 2015
New Revision: 247985

URL: http://llvm.org/viewvc/llvm-project?rev=247985&view=rev
Log:
[LazyValueInfo] Report nonnull range for nonnull pointers

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 additional nonnull instructions.

Differential Revision: http://reviews.llvm.org/D12932


Modified:
    llvm/trunk/lib/Analysis/LazyValueInfo.cpp
    llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll

Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=247985&r1=247984&r2=247985&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Fri Sep 18 08:01:48 2015
@@ -531,8 +531,10 @@ bool LazyValueInfoCache::solveBlockValue
     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.
+  PointerType *PT = dyn_cast<PointerType>(BBI->getType());
+  if (PT && isKnownNonNull(BBI)) {
+    Res = LVILatticeVal::getNot(ConstantPointerNull::get(PT));
     insertResult(Val, BB, Res);
     return true;
   }

Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll?rev=247985&r1=247984&r2=247985&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/non-null.ll Fri Sep 18 08:01:48 2015
@@ -140,3 +140,24 @@ merge:
   ; 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
+}




More information about the llvm-commits mailing list