Improve the precision of getConstant().
authorOwen Anderson <resistor@mac.com>
Fri, 27 Aug 2010 23:29:38 +0000 (23:29 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 27 Aug 2010 23:29:38 +0000 (23:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112323 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LazyValueInfo.cpp

index 7e00f143c65b16c63da22beb7525fa14563ecd90..e7929f3127bf928a511b1313e2f24d217105540a 100644 (file)
@@ -846,6 +846,11 @@ Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB) {
   
   if (Result.isConstant())
     return Result.getConstant();
+  else if (Result.isConstantRange()) {
+    ConstantRange CR = Result.getConstantRange();
+    if (const APInt *SingleVal = CR.getSingleElement())
+      return ConstantInt::get(V->getContext(), *SingleVal);
+  }
   return 0;
 }