diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 3f5da236af211..3028668ced629 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(C2); - if (!GV || !C1->isNullValue()) - return nullptr; - - // Don't try to evaluate aliases. External weak GV can be null. - if (!isa(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.