aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-11-03 14:21:16 +0100
committerNikita Popov <npopov@redhat.com>2023-11-03 14:24:08 +0100
commit9915ebaa5e596358b9b8b6753723b613b780b09c (patch)
tree5fbca71c9721cd0c24623075205ab007a321d25b /llvm/lib/IR/ConstantFold.cpp
parent17970df6dca3cf46f0264e94f40eb4ef93ef521f (diff)
downloadllvm-9915ebaa5e596358b9b8b6753723b613b780b09c.zip
llvm-9915ebaa5e596358b9b8b6753723b613b780b09c.tar.gz
llvm-9915ebaa5e596358b9b8b6753723b613b780b09c.tar.bz2
[ConstantFold] Remove redundant constantFoldCompareGlobalToNull() fold (NFCI)
This is already handled in evaluateICmpRelation().
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp27
1 files changed, 0 insertions, 27 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 3f5da23..3028668 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1252,25 +1252,6 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2) {
return ICmpInst::BAD_ICMP_PREDICATE;
}
-static Constant *constantFoldCompareGlobalToNull(CmpInst::Predicate Predicate,
- Constant *C1, Constant *C2) {
- const GlobalValue *GV = dyn_cast<GlobalValue>(C2);
- if (!GV || !C1->isNullValue())
- return nullptr;
-
- // Don't try to evaluate aliases. External weak GV can be null.
- if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage() &&
- !NullPointerIsDefined(nullptr /* F */,
- GV->getType()->getAddressSpace())) {
- if (Predicate == ICmpInst::ICMP_EQ)
- return ConstantInt::getFalse(C1->getContext());
- else if (Predicate == ICmpInst::ICMP_NE)
- return ConstantInt::getTrue(C1->getContext());
- }
-
- return nullptr;
-}
-
Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
Constant *C1, Constant *C2) {
Type *ResultTy;
@@ -1309,14 +1290,6 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
return ConstantInt::get(ResultTy, CmpInst::isUnordered(Predicate));
}
- // icmp eq/ne(null,GV) -> false/true
- if (Constant *Folded = constantFoldCompareGlobalToNull(Predicate, C1, C2))
- return Folded;
-
- // icmp eq/ne(GV,null) -> false/true
- if (Constant *Folded = constantFoldCompareGlobalToNull(Predicate, C2, C1))
- return Folded;
-
if (C2->isNullValue()) {
// The caller is expected to commute the operands if the constant expression
// is C2.