[LVI] Fix a latent bug in getValueAt
authorPhilip Reames <listmail@philipreames.com>
Tue, 2 Feb 2016 00:45:30 +0000 (00:45 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 2 Feb 2016 00:45:30 +0000 (00:45 +0000)
This routine was returning Undefined for most queries.  This was utterly wrong.  Amusingly, we do not appear to have any callers of this which are actually trying to exploit unreachable code or this would have broken the world.

A better approach would be to explicit describe the intersection of facts.  That's blocked behind http://reviews.llvm.org/D14476 and I wanted to fix the current bug.

llvm-svn: 259446

llvm/lib/Analysis/LazyValueInfo.cpp

index abc46c5..5d2bc19 100644 (file)
@@ -1128,6 +1128,14 @@ LVILatticeVal LazyValueInfoCache::getValueAt(Value *V, Instruction *CxtI) {
     Result = getFromRangeMetadata(I);
   mergeAssumeBlockValueConstantRange(V, Result, CxtI);
 
+  // Note: What's actually happening here is that we're starting at overdefined
+  // and then intersecting two different types of facts.  The code is not
+  // structured that way (FIXME), and we need to take particular care to not
+  // let the undefined state escape since we have *not* proven the particular
+  // value to be unreachable at the context instruction.
+  if (Result.isUndefined())
+    Result.markOverdefined();
+
   DEBUG(dbgs() << "  Result = " << Result << "\n");
   return Result;
 }