aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-10 22:53:04 +0000
committerChris Lattner <sabre@nondot.org>2007-12-10 22:53:04 +0000
commitf286f6fd93d569befe6e77c94a947e6e04e95685 (patch)
tree400c56bd0a897bc94b6b69e53505a2d1074cdb57 /lib/VMCore/ConstantFold.cpp
parent9324665a7845d6ffd23e3bd53443d28cbf2e75fa (diff)
downloadexternal_llvm-f286f6fd93d569befe6e77c94a947e6e04e95685.zip
external_llvm-f286f6fd93d569befe6e77c94a947e6e04e95685.tar.gz
external_llvm-f286f6fd93d569befe6e77c94a947e6e04e95685.tar.bz2
Fix PR1850 by removing an unsafe transformation from VMCore/ConstantFold.cpp.
Reimplement the xform in Analysis/ConstantFolding.cpp where we can use targetdata to validate that it is safe. While I'm in there, fix some const correctness issues and generalize the interface to the "operand folder". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 95140f3..5e5bbea 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -985,20 +985,19 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
case Instruction::UIToFP:
case Instruction::SIToFP:
- case Instruction::IntToPtr:
case Instruction::BitCast:
case Instruction::ZExt:
case Instruction::SExt:
- case Instruction::PtrToInt:
// If the cast is not actually changing bits, and the second operand is a
// null pointer, do the comparison with the pre-casted value.
if (V2->isNullValue() &&
(isa<PointerType>(CE1->getType()) || CE1->getType()->isInteger())) {
- bool sgnd = CE1->getOpcode() == Instruction::ZExt ? false :
- (CE1->getOpcode() == Instruction::SExt ? true :
- (CE1->getOpcode() == Instruction::PtrToInt ? false : isSigned));
- return evaluateICmpRelation(
- CE1Op0, Constant::getNullValue(CE1Op0->getType()), sgnd);
+ bool sgnd = isSigned;
+ if (CE1->getOpcode() == Instruction::ZExt) isSigned = false;
+ if (CE1->getOpcode() == Instruction::SExt) isSigned = true;
+ return evaluateICmpRelation(CE1Op0,
+ Constant::getNullValue(CE1Op0->getType()),
+ sgnd);
}
// If the dest type is a pointer type, and the RHS is a constantexpr cast
@@ -1009,11 +1008,11 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
if (CE2->isCast() && isa<PointerType>(CE1->getType()) &&
CE1->getOperand(0)->getType() == CE2->getOperand(0)->getType() &&
CE1->getOperand(0)->getType()->isInteger()) {
- bool sgnd = CE1->getOpcode() == Instruction::ZExt ? false :
- (CE1->getOpcode() == Instruction::SExt ? true :
- (CE1->getOpcode() == Instruction::PtrToInt ? false : isSigned));
+ bool sgnd = isSigned;
+ if (CE1->getOpcode() == Instruction::ZExt) isSigned = false;
+ if (CE1->getOpcode() == Instruction::SExt) isSigned = true;
return evaluateICmpRelation(CE1->getOperand(0), CE2->getOperand(0),
- sgnd);
+ sgnd);
}
break;