diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-03 17:27:15 +0000 | 
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-03-03 17:27:15 +0000 | 
| commit | 67a71b3184ce20a901e874d0ee25e01397dd87ef (patch) | |
| tree | 836a05cff50ca46176117b86029f061fa4db54f0 /lib/Analysis/ConstantFolding.cpp | |
| parent | 6fe5c7aa327e188b7176daa5595bbf075a6b94df (diff) | |
Notes
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
| -rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 53 | 
1 files changed, 13 insertions, 40 deletions
| diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 808e6fa38c5d..114db2d37050 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -359,7 +359,7 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,        MapTy = Type::getInt32PtrTy(C->getContext());      else if (LoadTy->isDoubleTy())        MapTy = Type::getInt64PtrTy(C->getContext()); -    else if (isa<VectorType>(LoadTy)) { +    else if (LoadTy->isVectorTy()) {        MapTy = IntegerType::get(C->getContext(),                                 TD.getTypeAllocSizeInBits(LoadTy));        MapTy = PointerType::getUnqual(MapTy); @@ -605,7 +605,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps,    SmallVector<Constant*, 32> NewIdxs;    do {      if (const SequentialType *ATy = dyn_cast<SequentialType>(Ty)) { -      if (isa<PointerType>(ATy)) { +      if (ATy->isPointerTy()) {          // The only pointer indexing we'll do is on the first index of the GEP.          if (!NewIdxs.empty())            break; @@ -783,45 +783,12 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,      // If the input is a ptrtoint, turn the pair into a ptr to ptr bitcast if      // the int size is >= the ptr size.  This requires knowing the width of a      // pointer, so it can't be done in ConstantExpr::getCast. -    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) { +    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0]))        if (TD && -          TD->getPointerSizeInBits() <= -          CE->getType()->getScalarSizeInBits()) { -        if (CE->getOpcode() == Instruction::PtrToInt) -          return FoldBitCast(CE->getOperand(0), DestTy, *TD); -         -        // If there's a constant offset added to the integer value before -        // it is casted back to a pointer, see if the expression can be -        // converted into a GEP. -        if (CE->getOpcode() == Instruction::Add) -          if (ConstantInt *L = dyn_cast<ConstantInt>(CE->getOperand(0))) -            if (ConstantExpr *R = dyn_cast<ConstantExpr>(CE->getOperand(1))) -              if (R->getOpcode() == Instruction::PtrToInt) -                if (GlobalVariable *GV = -                      dyn_cast<GlobalVariable>(R->getOperand(0))) { -                  const PointerType *GVTy = cast<PointerType>(GV->getType()); -                  if (const ArrayType *AT = -                        dyn_cast<ArrayType>(GVTy->getElementType())) { -                    const Type *ElTy = AT->getElementType(); -                    uint64_t AllocSize = TD->getTypeAllocSize(ElTy); -                    APInt PSA(L->getValue().getBitWidth(), AllocSize); -                    if (ElTy == cast<PointerType>(DestTy)->getElementType() && -                        L->getValue().urem(PSA) == 0) { -                      APInt ElemIdx = L->getValue().udiv(PSA); -                      if (ElemIdx.ult(APInt(ElemIdx.getBitWidth(), -                                            AT->getNumElements()))) { -                        Constant *Index[] = { -                          Constant::getNullValue(CE->getType()), -                          ConstantInt::get(ElTy->getContext(), ElemIdx) -                        }; -                        return -                        ConstantExpr::getGetElementPtr(GV, &Index[0], 2); -                      } -                    } -                  } -                } -      } -    } +          TD->getPointerSizeInBits() <= CE->getType()->getScalarSizeInBits() && +          CE->getOpcode() == Instruction::PtrToInt) +        return FoldBitCast(CE->getOperand(0), DestTy, *TD); +      return ConstantExpr::getCast(Opcode, Ops[0], DestTy);    case Instruction::Trunc:    case Instruction::ZExt: @@ -1179,6 +1146,12 @@ llvm::ConstantFoldCall(Function *F,        return 0;      } +    if (isa<UndefValue>(Operands[0])) { +      if (Name.startswith("llvm.bswap")) +        return Operands[0]; +      return 0; +    } +      return 0;    } | 
