summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-06 22:24:29 +0000
committerChris Lattner <sabre@nondot.org>2011-01-06 22:24:29 +0000
commitf1cadf28991b2643128bfe38990ff235f2cb1491 (patch)
tree681e711a45cd4e14cf5985f9ff407575c411dd92 /lib
parent76a788c886376d451ae3baa55429bf2d19039e9e (diff)
downloadllvm-f1cadf28991b2643128bfe38990ff235f2cb1491.tar.gz
llvm-f1cadf28991b2643128bfe38990ff235f2cb1491.tar.bz2
llvm-f1cadf28991b2643128bfe38990ff235f2cb1491.tar.xz
use isNullValue() to simplify code, add an assert.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/ConstantFolding.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 6c5b75502f..cc9f367ff0 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/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));