diff options
author | Chris Lattner <sabre@nondot.org> | 2011-01-06 22:24:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-01-06 22:24:29 +0000 |
commit | 171608e738a40d85a5fda467b1011234aaf54b73 (patch) | |
tree | d7099e72b71964a95e8197156c8bf800e6238c0b /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 5ccbd294b25d2666c42b28c7031c8e0eff197f25 (diff) | |
download | bcm5719-llvm-171608e738a40d85a5fda467b1011234aaf54b73.tar.gz bcm5719-llvm-171608e738a40d85a5fda467b1011234aaf54b73.zip |
use isNullValue() to simplify code, add an assert.
llvm-svn: 122977
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 6c5b75502fa..cc9f367ff0a 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -568,9 +568,8 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps, Constant *Ptr = Ops[0]; if (!TD || !cast<PointerType>(Ptr->getType())->getElementType()->isSized()) return 0; - - unsigned BitWidth = - TD->getTypeSizeInBits(TD->getIntPtrType(Ptr->getContext())); + + const Type *IntPtrTy = TD->getIntPtrType(Ptr->getContext()); // If this is a constant expr gep that is effectively computing an // "offsetof", fold it into 'cast int Size to T*' instead of 'gep 0, 0, 12' @@ -582,9 +581,10 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps, if (NumOps == 2 && cast<PointerType>(ResultTy)->getElementType()->isIntegerTy(8)) { ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[1]); + assert(CE->getType() == IntPtrTy && + "CastGEPIndices didn't canonicalize index types!"); if (CE && CE->getOpcode() == Instruction::Sub && - isa<ConstantInt>(CE->getOperand(0)) && - cast<ConstantInt>(CE->getOperand(0))->isZero()) { + CE->getOperand(0)->isNullValue()) { Constant *Res = ConstantExpr::getPtrToInt(Ptr, CE->getType()); Res = ConstantExpr::getSub(Res, CE->getOperand(1)); Res = ConstantExpr::getIntToPtr(Res, ResultTy); @@ -596,6 +596,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps, return 0; } + unsigned BitWidth = TD->getTypeSizeInBits(IntPtrTy); APInt Offset = APInt(BitWidth, TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1)); |