aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2013-01-31 00:01:45 +0000
committerDan Gohman <dan433584@gmail.com>2013-01-31 00:01:45 +0000
commit6a61fccb96a693fef6f4e88cf597d403c3ccc8a4 (patch)
treedbf6a2135815dc6d1ae43e5910ae156c04186adb /llvm/lib/IR/ConstantFold.cpp
parent606acb7c853fc09de94584b19d320db6da20e769 (diff)
downloadllvm-6a61fccb96a693fef6f4e88cf597d403c3ccc8a4.zip
llvm-6a61fccb96a693fef6f4e88cf597d403c3ccc8a4.tar.gz
llvm-6a61fccb96a693fef6f4e88cf597d403c3ccc8a4.tar.bz2
Fix ConstantFold's folding of icmp instructions to recognize that,
for example, a one-past-the-end pointer from one global variable may be equal to the base pointer of another global variable. llvm-svn: 173995
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 417e0d1..587b7ce8 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1495,9 +1495,8 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
"Surprising getelementptr!");
return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
} else {
- // If they are different globals, we don't know what the value is,
- // but they can't be equal.
- return ICmpInst::ICMP_NE;
+ // If they are different globals, we don't know what the value is.
+ return ICmpInst::BAD_ICMP_PREDICATE;
}
}
} else {
@@ -1510,10 +1509,10 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
default: break;
case Instruction::GetElementPtr:
// By far the most common case to handle is when the base pointers are
- // obviously to the same or different globals.
+ // obviously to the same global.
if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
- if (CE1Op0 != CE2Op0) // Don't know relative ordering, but not equal
- return ICmpInst::ICMP_NE;
+ if (CE1Op0 != CE2Op0) // Don't know relative ordering.
+ return ICmpInst::BAD_ICMP_PREDICATE;
// Ok, we know that both getelementptr instructions are based on the
// same global. From this, we can precisely determine the relative
// ordering of the resultant pointers.