Add comment.
[oota-llvm.git] / lib / Transforms / Scalar / PredicateSimplifier.cpp
index 972e875d4b0d04307b652eed3e4b1af836e4343a..42ffc0edc2564b47fed8a7dc91ace9da390a7a43 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Nick Lewycky and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -711,21 +711,23 @@ namespace {
           ++J;
         }
 
-        if (J != E && J->To == n && J->Subtree->dominates(Subtree)) {
+        if (J != E && J->To == n) {
           edge.LV = static_cast<LatticeVal>(J->LV & R);
           assert(validPredicate(edge.LV) && "Invalid union of lattice values.");
-          if (edge.LV != J->LV) {
-
-            // We have to tighten any edge beneath our update.
-            for (iterator K = I; K->To == n; --K) {
-              if (K->Subtree->DominatedBy(Subtree)) {
-                LatticeVal LV = static_cast<LatticeVal>(K->LV & edge.LV);
-                assert(validPredicate(LV) && "Invalid union of lattice values");
-                K->LV = LV;
-              }
-              if (K == B) break;
-            }
 
+          if (edge.LV == J->LV)
+            return; // This update adds nothing new.
+        }
+
+        if (I != B) {
+          // We also have to tighten any edge beneath our update.
+          for (iterator K = I - 1; K->To == n; --K) {
+            if (K->Subtree->DominatedBy(Subtree)) {
+              LatticeVal LV = static_cast<LatticeVal>(K->LV & edge.LV);
+              assert(validPredicate(LV) && "Invalid union of lattice values");
+              K->LV = LV;
+            }
+            if (K == B) break;
           }
         }
 
@@ -1110,7 +1112,7 @@ namespace {
       else if (isa<ConstantPointerNull>(V))
         return ConstantRange(APInt::getNullValue(typeToWidth(V->getType())));
       else
-        return typeToWidth(V->getType());
+        return ConstantRange(typeToWidth(V->getType()));
     }
 
     // typeToWidth - returns the number of bits necessary to store a value of
@@ -1118,11 +1120,8 @@ namespace {
     uint32_t typeToWidth(const Type *Ty) const {
       if (TD)
         return TD->getTypeSizeInBits(Ty);
-
-      if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty))
-        return ITy->getBitWidth();
-
-      return 0;
+      else
+        return Ty->getPrimitiveSizeInBits();
     }
 
     static bool isRelatedBy(const ConstantRange &CR1, const ConstantRange &CR2,
@@ -1999,7 +1998,7 @@ namespace {
               if (!isRelatedBy(Known, Zero, ICmpInst::ICMP_NE)) break;
               // otherwise, fall-through.
             case Instruction::Sub:
-              if (Unknown == Op1) break;
+              if (Unknown == Op0) break;
               // otherwise, fall-through.
             case Instruction::Xor:
             case Instruction::Add: