[llvm] 9915eba - [ConstantFold] Remove redundant constantFoldCompareGlobalToNull() fold (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 06:24:19 PDT 2023


Author: Nikita Popov
Date: 2023-11-03T14:24:08+01:00
New Revision: 9915ebaa5e596358b9b8b6753723b613b780b09c

URL: https://github.com/llvm/llvm-project/commit/9915ebaa5e596358b9b8b6753723b613b780b09c
DIFF: https://github.com/llvm/llvm-project/commit/9915ebaa5e596358b9b8b6753723b613b780b09c.diff

LOG: [ConstantFold] Remove redundant constantFoldCompareGlobalToNull() fold (NFCI)

This is already handled in evaluateICmpRelation().

Added: 
    

Modified: 
    llvm/lib/IR/ConstantFold.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 3f5da236af211f6..3028668ced62931 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.


        


More information about the llvm-commits mailing list