Add support for removing invoke instructions
[oota-llvm.git] / lib / Transforms / LevelRaise.cpp
index c128688da2f732e3973d2c45402916e6f53cb600..aeb836d4b7e4fbf9aba15e69d522227badaa413f 100644 (file)
@@ -370,25 +370,22 @@ bool RPR::PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
           // Build the index vector, full of all zeros
           std::vector<Value*> Indices;
 
-          Indices.push_back(ConstantSInt::get(Type::LongTy, 0)); // FIXME, PR82
+          Indices.push_back(Constant::getNullValue(Type::UIntTy));
           while (CurCTy && !isa<PointerType>(CurCTy)) {
-            const Type *IdxType;
             if (const StructType *CurSTy = dyn_cast<StructType>(CurCTy)) {
               // Check for a zero element struct type... if we have one, bail.
-              if (CurSTy->getElementTypes().size() == 0) break;
+              if (CurSTy->getNumElements() == 0) break;
             
               // Grab the first element of the struct type, which must lie at
               // offset zero in the struct.
               //
-              ElTy = CurSTy->getElementTypes()[0];
-              IdxType = Type::UByteTy;   // FIXME when PR82 is fixed.
+              ElTy = CurSTy->getElementType(0);
             } else {
               ElTy = cast<ArrayType>(CurCTy)->getElementType();
-              IdxType = Type::LongTy;    // FIXME when PR82 is fixed.
             }
 
             // Insert a zero to index through this type...
-            Indices.push_back(Constant::getNullValue(IdxType));
+            Indices.push_back(Constant::getNullValue(Type::UIntTy));
 
             // Did we find what we're looking for?
             if (ElTy->isLosslesslyConvertibleTo(DestPointedTy)) break;
@@ -539,6 +536,10 @@ bool RPR::PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
         NewCast = new CastInst(CI->getCalledValue(), NewPFunTy,
                                CI->getCalledValue()->getName()+"_c",CI);
 
+      // Strip off unneeded CPR's.
+      if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(NewCast))
+        NewCast = CPR->getValue();
+
       // Create a new call instruction...
       CallInst *NewCall = new CallInst(NewCast,
                            std::vector<Value*>(CI->op_begin()+1, CI->op_end()));