summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-01-28 18:08:26 +0000
committerDan Gohman <gohman@apple.com>2010-01-28 18:08:26 +0000
commita424b9fbd16bbca930b62110a1f52cc155d0a91b (patch)
tree0f04ba2cd8c86052e1981f81c0ff2f90d714fb3e /llvm/lib/VMCore/ConstantFold.cpp
parent29063eac2309c996aa8d23a0abf596c524d6cb89 (diff)
downloadbcm5719-llvm-a424b9fbd16bbca930b62110a1f52cc155d0a91b.tar.gz
bcm5719-llvm-a424b9fbd16bbca930b62110a1f52cc155d0a91b.zip
Remove the folding rule
getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1) to inttoptr (i64 0 to i8*) from the VMCore constant folder. It didn't handle sign-extension properly in the case where the source integer is smaller than a pointer size. And, it relied on an assumption about sizeof(i8). The Analysis constant folder still folds these kinds of things; it has access to TargetData, so it can do them right. Add a testcase which tests that the VMCore constant folder doesn't miscompile this, and that the Analysis folder does fold it. llvm-svn: 94750
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp22
1 files changed, 0 insertions, 22 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 24b78ae969a..40061ee3d7b 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -2021,28 +2021,6 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
ConstantExpr::getGetElementPtr(
(Constant*)CE->getOperand(0), Idxs, NumIdx);
}
-
- // Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1)
- // Into: inttoptr (i64 0 to i8*)
- // This happens with pointers to member functions in C++.
- if (CE->getOpcode() == Instruction::IntToPtr && NumIdx == 1 &&
- isa<ConstantInt>(CE->getOperand(0)) && isa<ConstantInt>(Idxs[0]) &&
- cast<PointerType>(CE->getType())->getElementType() ==
- Type::getInt8Ty(Context)) {
- Constant *Base = CE->getOperand(0);
- Constant *Offset = Idxs[0];
-
- // Convert the smaller integer to the larger type.
- if (Offset->getType()->getPrimitiveSizeInBits() <
- Base->getType()->getPrimitiveSizeInBits())
- Offset = ConstantExpr::getSExt(Offset, Base->getType());
- else if (Base->getType()->getPrimitiveSizeInBits() <
- Offset->getType()->getPrimitiveSizeInBits())
- Base = ConstantExpr::getZExt(Base, Offset->getType());
-
- Base = ConstantExpr::getAdd(Base, Offset);
- return ConstantExpr::getIntToPtr(Base, CE->getType());
- }
}
// Check to see if any array indices are not within the corresponding
OpenPOWER on IntegriCloud