Add facility that allows LoopPass to re-insert a loop into
[oota-llvm.git] / lib / Analysis / ConstantFolding.cpp
index 8a690feed1e5930d38ed590122e94b1168f46ca5..01aedda63538dd60163020f17c79bf81b28df84e 100644 (file)
@@ -70,7 +70,7 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
       
       if (const StructType *ST = dyn_cast<StructType>(*GTI)) {
         // N = N + Offset
-        Offset += TD.getStructLayout(ST)->MemberOffsets[CI->getZExtValue()];
+        Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
       } else {
         const SequentialType *ST = cast<SequentialType>(*GTI);
         Offset += TD.getTypeSize(ST->getElementType())*CI->getSExtValue();
@@ -133,8 +133,8 @@ static Constant *SymbolicallyEvaluateGEP(Constant** Ops, unsigned NumOps,
         break;
       }
     if (isFoldableGEP) {
-      std::vector<Value*> NewOps(Ops+1, Ops+NumOps);
-      uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), NewOps);
+      uint64_t Offset = TD->getIndexedOffset(Ptr->getType(),
+                                             (Value**)Ops+1, NumOps-1);
       Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset);
       return ConstantExpr::getIntToPtr(C, ResultTy);
     }
@@ -210,16 +210,12 @@ Constant *llvm::ConstantFoldInstOperands(const Instruction* I,
   case Instruction::Call:
     if (Function *F = dyn_cast<Function>(Ops[0]))
       if (canConstantFoldCallTo(F))
-        return ConstantFoldCall(F, Ops+1, NumOps);
+        return ConstantFoldCall(F, Ops+1, NumOps-1);
     return 0;
   case Instruction::ICmp:
   case Instruction::FCmp:
     return ConstantExpr::getCompare(cast<CmpInst>(I)->getPredicate(), Ops[0], 
                                     Ops[1]);
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
-    return ConstantExpr::get(Opc, Ops[0], Ops[1]);
   case Instruction::Trunc:
   case Instruction::ZExt:
   case Instruction::SExt:
@@ -287,10 +283,10 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
           C = UndefValue::get(ATy->getElementType());
         else
           return 0;
-      } else if (const PackedType *PTy = dyn_cast<PackedType>(*I)) {
+      } else if (const VectorType *PTy = dyn_cast<VectorType>(*I)) {
         if (CI->getZExtValue() >= PTy->getNumElements())
           return 0;
-        if (ConstantPacked *CP = dyn_cast<ConstantPacked>(C))
+        if (ConstantVector *CP = dyn_cast<ConstantVector>(C))
           C = CP->getOperand(CI->getZExtValue());
         else if (isa<ConstantAggregateZero>(C))
           C = Constant::getNullValue(PTy->getElementType());