Unbreak the build.
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index 5138031da9186494fef609420be860e0d75eef1d..07df0bfba053789508a06b80dc3a657c0b568423 100644 (file)
@@ -447,6 +447,21 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(const Constant *V1,
   return ConstantVector::get(&Result[0], Result.size());
 }
 
+Constant *llvm::ConstantFoldExtractValue(const Constant *Agg,
+                                         Constant* const *Idxs,
+                                         unsigned NumIdx) {
+  // FIXME: implement some constant folds
+  return 0;
+}
+
+Constant *llvm::ConstantFoldInsertValue(const Constant *Agg,
+                                        const Constant *Val,
+                                        Constant* const *Idxs,
+                                        unsigned NumIdx) {
+  // FIXME: implement some constant folds
+  return 0;
+}
+
 /// EvalVectorOp - Given two vector constants and a function pointer, apply the
 /// function pointer to each element pair, producing a new ConstantVector
 /// constant. Either or both of V1 and V2 may be NULL, meaning a
@@ -1014,6 +1029,29 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
         }
       break;
 
+    case Instruction::PtrToInt:
+    case Instruction::IntToPtr:
+      // inttoptr(x1) != inttoptr(x2) iff x1 != x2
+      if (const ConstantExpr *CE2 = dyn_cast<ConstantExpr>(V2))
+        if (CE1->getOpcode() == CE2->getOpcode()) {
+          Constant *Op1 = const_cast<Constant*>(CE1Op0);
+          Constant *Op2 = CE2->getOperand(0);
+          if (Op1->getType() == Op2->getType()) {
+            ConstantInt *R = 0;
+
+            ICmpInst::Predicate pred = ICmpInst::ICMP_EQ;
+            R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, Op1, Op2));
+            if (R && !R->isZero()) 
+              return pred;
+
+            pred = ICmpInst::ICMP_NE;
+            R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, Op1, Op2));
+            if (R && !R->isZero()) 
+              return pred;
+          }
+        }
+      break;
+
     case Instruction::GetElementPtr:
       // Ok, since this is a getelementptr, we know that the constant has a
       // pointer type.  Check the various cases.
@@ -1408,8 +1446,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
     const PointerType *Ptr = cast<PointerType>(C->getType());
     const Type *Ty = GetElementPtrInst::getIndexedType(Ptr,
                                                        (Value **)Idxs,
-                                                       (Value **)Idxs+NumIdx,
-                                                       true);
+                                                       (Value **)Idxs+NumIdx);
     assert(Ty != 0 && "Invalid indices for GEP!");
     return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
   }
@@ -1426,8 +1463,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
       const PointerType *Ptr = cast<PointerType>(C->getType());
       const Type *Ty = GetElementPtrInst::getIndexedType(Ptr,
                                                          (Value**)Idxs,
-                                                         (Value**)Idxs+NumIdx,
-                                                         true);
+                                                         (Value**)Idxs+NumIdx);
       assert(Ty != 0 && "Invalid indices for GEP!");
       return 
         ConstantPointerNull::get(PointerType::get(Ty,Ptr->getAddressSpace()));