[llvm] r262751 - [LVI] Fix a bug which prevented use of !range metadata within a query

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 14:27:39 PST 2016


Author: reames
Date: Fri Mar  4 16:27:39 2016
New Revision: 262751

URL: http://llvm.org/viewvc/llvm-project?rev=262751&view=rev
Log:
[LVI] Fix a bug which prevented use of !range metadata within a query

The diff is relatively large since I took a chance to rearrange the code I had to touch in a more obvious way, but the key bit is merely using the !range metadata when we can't analyze the instruction further.  The previous !range metadata code was essentially just dead since no binary operator or cast will have !range metadata (per Verifier) and it was otherwise dropped on the floor.


Modified:
    llvm/trunk/lib/Analysis/LazyValueInfo.cpp
    llvm/trunk/test/Transforms/CorrelatedValuePropagation/range.ll

Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=262751&r1=262750&r2=262751&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Fri Mar  4 16:27:39 2016
@@ -669,36 +669,24 @@ bool LazyValueInfoCache::solveBlockValue
     return true;
   }
 
-  // If this is an instruction which supports range metadata, intersect the
-  // implied range.
-  Res = intersect(Res, getFromRangeMetadata(BBI));
-
-  // We can only analyze the definitions of certain classes of instructions
-  // (integral binops and casts at the moment), so bail if this isn't one.
-  LVILatticeVal Result;
-  if ((!isa<BinaryOperator>(BBI) && !isa<CastInst>(BBI)) ||
-     !BBI->getType()->isIntegerTy()) {
-    DEBUG(dbgs() << " compute BB '" << BB->getName()
-                 << "' - overdefined because inst def found.\n");
-    Res.markOverdefined();
+  if (isa<CastInst>(BBI) && BBI->getType()->isIntegerTy()) {
+    if (!solveBlockValueConstantRange(Res, BBI, BB))
+      return false;
     insertResult(Val, BB, Res);
     return true;
   }
 
-  // FIXME: We're currently limited to binops with a constant RHS.  This should
-  // be improved.
   BinaryOperator *BO = dyn_cast<BinaryOperator>(BBI);
-  if (BO && !isa<ConstantInt>(BO->getOperand(1))) { 
-    DEBUG(dbgs() << " compute BB '" << BB->getName()
-                 << "' - overdefined because inst def found.\n");
-
-    Res.markOverdefined();
+  if (BO && isa<ConstantInt>(BO->getOperand(1))) { 
+    if (!solveBlockValueConstantRange(Res, BBI, BB))
+      return false;
     insertResult(Val, BB, Res);
     return true;
   }
 
-  if (!solveBlockValueConstantRange(Res, BBI, BB))
-    return false;
+  DEBUG(dbgs() << " compute BB '" << BB->getName()
+                 << "' - unknown inst def found.\n");
+  Res = getFromRangeMetadata(BBI);
   insertResult(Val, BB, Res);
   return true;
 }
@@ -1007,7 +995,7 @@ bool LazyValueInfoCache::solveBlockValue
 
 bool LazyValueInfoCache::solveBlockValueConstantRange(LVILatticeVal &BBLV,
                                                       Instruction *BBI,
-                                                      BasicBlock *BB) {
+                                                      BasicBlock *BB) {  
   // Figure out the range of the LHS.  If that fails, bail.
   if (!hasBlockValue(BBI->getOperand(0), BB)) {
     if (pushBlockValue(std::make_pair(BB, BBI->getOperand(0))))

Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/range.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/range.ll?rev=262751&r1=262750&r2=262751&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/range.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/range.ll Fri Mar  4 16:27:39 2016
@@ -189,3 +189,17 @@ define i1 @test10(i64* %p) {
   %res = icmp eq i64 %a, 0
   ret i1 %res
 }
+
+ at g = external global i32
+
+define i1 @test11() {
+; CHECK: @test11
+; CHECK: ret i1 true
+  %positive = load i32, i32* @g, !range !{i32 1, i32 2048}
+  %add = add i32 %positive, 1
+  %test = icmp sgt i32 %add, 0
+  br label %next
+
+next:
+  ret i1 %test
+}




More information about the llvm-commits mailing list