Clean up logic after ConstantBool removal.
authorNick Lewycky <nicholas@mxc.ca>
Fri, 12 Jan 2007 00:02:12 +0000 (00:02 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Fri, 12 Jan 2007 00:02:12 +0000 (00:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33096 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/PredicateSimplifier.cpp

index c577409f9a49c2a599b4aff5644a3b7da53b3c13..8defb871b763db1773ec029a23d94a2dbb7b1739 100644 (file)
@@ -432,11 +432,8 @@ namespace {
       NodeMap.insert(std::lower_bound(NodeMap.begin(), NodeMap.end(),
                                       MapEntry), MapEntry);
 
-#if 1
-      // This is the missing piece to turn on VRP.
       if (Constant *C = dyn_cast<Constant>(V))
         initializeConstant(C, MapEntry.index);
-#endif
 
       return MapEntry.index;
     }
@@ -1127,14 +1124,12 @@ namespace {
             Value *RHS = Op1;
             if (!isa<Constant>(LHS)) std::swap(LHS, RHS);
 
-            ConstantInt *CB, *A;
-            if ((CB = dyn_cast<ConstantInt>(Canonical)) && 
-                CB->getType() == Type::Int1Ty) {
-              if ((A = dyn_cast<ConstantInt>(LHS)) &&
-                  A->getType() == Type::Int1Ty)
-                add(RHS, ConstantInt::get(A->getBoolValue() ^ 
-                                          CB->getBoolValue()),
-                                          ICmpInst::ICMP_EQ, NewContext);
+            if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) {
+              if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) {
+                add(RHS, ConstantInt::get(CI->getType(), CI->getZExtValue() ^
+                                          Arg->getZExtValue()),
+                    ICmpInst::ICMP_EQ, NewContext);
+              }
             }
             if (Canonical == LHS) {
               if (isa<ConstantInt>(Canonical))
@@ -1238,21 +1233,18 @@ namespace {
             case Instruction::Or:
             case Instruction::Add:
             case Instruction::Sub:
-              add(Unknown, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ, NewContext);
+              add(Unknown, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ,
+                  NewContext);
               break;
             case Instruction::UDiv:
             case Instruction::SDiv:
               if (Unknown == Op0) break; // otherwise, fallthrough
             case Instruction::And:
             case Instruction::Mul:
-              Constant *One = NULL;
-              if (isa<ConstantInt>(Unknown))
-                One = ConstantInt::get(Ty, 1);
-              else if (isa<ConstantInt>(Unknown) && 
-                       Unknown->getType() == Type::Int1Ty)
-                One = ConstantInt::getTrue();
-
-              if (One) add(Unknown, One, ICmpInst::ICMP_EQ, NewContext);
+              if (isa<ConstantInt>(Unknown)) {
+                Constant *One = ConstantInt::get(Ty, 1);
+                add(Unknown, One, ICmpInst::ICMP_EQ, NewContext);
+              }
               break;
           }
         }
@@ -1274,6 +1266,8 @@ namespace {
           add(IC, ConstantInt::getFalse(), ICmpInst::ICMP_EQ, NewContext);
         }
 
+        // TODO: "bool %x s<u> %y" implies %x = true and %y = false.
+
         // TODO: make the predicate more strict, if possible.
 
       } else if (SelectInst *SI = dyn_cast<SelectInst>(I)) {