[llvm-commits] [llvm] r122977 - /llvm/trunk/lib/Analysis/ConstantFolding.cpp
Chris Lattner
sabre at nondot.org
Thu Jan 6 14:24:29 PST 2011
Author: lattner
Date: Thu Jan 6 16:24:29 2011
New Revision: 122977
URL: http://llvm.org/viewvc/llvm-project?rev=122977&view=rev
Log:
use isNullValue() to simplify code, add an assert.
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=122977&r1=122976&r2=122977&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Thu Jan 6 16:24:29 2011
@@ -568,9 +568,8 @@
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 @@
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 @@
return 0;
}
+ unsigned BitWidth = TD->getTypeSizeInBits(IntPtrTy);
APInt Offset = APInt(BitWidth,
TD->getIndexedOffset(Ptr->getType(),
(Value**)Ops+1, NumOps-1));
More information about the llvm-commits
mailing list