diff options
author | Chris Lattner <sabre@nondot.org> | 2007-12-10 22:53:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-12-10 22:53:04 +0000 |
commit | d6e569110ab0ff7846c184f1c92effd798ff39a8 (patch) | |
tree | 400c56bd0a897bc94b6b69e53505a2d1074cdb57 /lib/VMCore/ConstantFold.cpp | |
parent | 844fad5f440c7a69112c2f8f17bbc488232a6893 (diff) | |
download | external_llvm-d6e569110ab0ff7846c184f1c92effd798ff39a8.zip external_llvm-d6e569110ab0ff7846c184f1c92effd798ff39a8.tar.gz external_llvm-d6e569110ab0ff7846c184f1c92effd798ff39a8.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.cpp | 21 |
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; |