Skip to content

Commit 9915eba

Browse files
committed
[ConstantFold] Remove redundant constantFoldCompareGlobalToNull() fold (NFCI)
This is already handled in evaluateICmpRelation().
1 parent 17970df commit 9915eba

File tree

1 file changed

+0
-27
lines changed

1 file changed

+0
-27
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,25 +1252,6 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2) {
12521252
return ICmpInst::BAD_ICMP_PREDICATE;
12531253
}
12541254

1255-
static Constant *constantFoldCompareGlobalToNull(CmpInst::Predicate Predicate,
1256-
Constant *C1, Constant *C2) {
1257-
const GlobalValue *GV = dyn_cast<GlobalValue>(C2);
1258-
if (!GV || !C1->isNullValue())
1259-
return nullptr;
1260-
1261-
// Don't try to evaluate aliases. External weak GV can be null.
1262-
if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage() &&
1263-
!NullPointerIsDefined(nullptr /* F */,
1264-
GV->getType()->getAddressSpace())) {
1265-
if (Predicate == ICmpInst::ICMP_EQ)
1266-
return ConstantInt::getFalse(C1->getContext());
1267-
else if (Predicate == ICmpInst::ICMP_NE)
1268-
return ConstantInt::getTrue(C1->getContext());
1269-
}
1270-
1271-
return nullptr;
1272-
}
1273-
12741255
Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
12751256
Constant *C1, Constant *C2) {
12761257
Type *ResultTy;
@@ -1309,14 +1290,6 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
13091290
return ConstantInt::get(ResultTy, CmpInst::isUnordered(Predicate));
13101291
}
13111292

1312-
// icmp eq/ne(null,GV) -> false/true
1313-
if (Constant *Folded = constantFoldCompareGlobalToNull(Predicate, C1, C2))
1314-
return Folded;
1315-
1316-
// icmp eq/ne(GV,null) -> false/true
1317-
if (Constant *Folded = constantFoldCompareGlobalToNull(Predicate, C2, C1))
1318-
return Folded;
1319-
13201293
if (C2->isNullValue()) {
13211294
// The caller is expected to commute the operands if the constant expression
13221295
// is C2.

0 commit comments

Comments
 (0)