aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2021-12-28 14:09:34 +0100
committerNikita Popov <npopov@redhat.com>2021-12-28 14:13:33 +0100
commit23de66d1636b53ff4e52be91f6b84f014a6ae279 (patch)
treed24e1c6c84aa8e6b430d60beb51c6da77686c4d5 /llvm/lib/IR/ConstantFold.cpp
parent1bd11d34feecde09958669f6c507b9a10cc6b2ab (diff)
downloadllvm-23de66d1636b53ff4e52be91f6b84f014a6ae279.zip
llvm-23de66d1636b53ff4e52be91f6b84f014a6ae279.tar.gz
llvm-23de66d1636b53ff4e52be91f6b84f014a6ae279.tar.bz2
[ConstFold] Don't fold signed comparison of gep of global
An inbounds GEP may still cross the sign boundary, so signed icmps cannot be folded (https://alive2.llvm.org/ce/z/XSgi4D). This was previously fixed for other folds in this function, but this one was missed.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 8668fe8..ae926f9 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1668,8 +1668,8 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
++i, ++GTI)
switch (IdxCompare(CE1->getOperand(i),
CE2->getOperand(i), GTI.getIndexedType())) {
- case -1: return isSigned ? ICmpInst::ICMP_SLT:ICmpInst::ICMP_ULT;
- case 1: return isSigned ? ICmpInst::ICMP_SGT:ICmpInst::ICMP_UGT;
+ case -1: return ICmpInst::ICMP_ULT;
+ case 1: return ICmpInst::ICMP_UGT;
case -2: return ICmpInst::BAD_ICMP_PREDICATE;
}
@@ -1678,7 +1678,7 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
for (; i < CE1->getNumOperands(); ++i)
if (!CE1->getOperand(i)->isNullValue()) {
if (isa<ConstantInt>(CE1->getOperand(i)))
- return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
+ return ICmpInst::ICMP_UGT;
else
return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal.
}
@@ -1686,7 +1686,7 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
for (; i < CE2->getNumOperands(); ++i)
if (!CE2->getOperand(i)->isNullValue()) {
if (isa<ConstantInt>(CE2->getOperand(i)))
- return isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
+ return ICmpInst::ICMP_ULT;
else
return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal.
}