Skip to content

Commit 1379eb5

Browse files
committed
[ConstFold] Slightly clean up icmp of two geps fold (NFC)
As we're only dealing with one type of constant expression here, try to directly cast to GEPOperator.
1 parent 75db002 commit 1379eb5

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,26 +1553,17 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
15531553
return ICmpInst::BAD_ICMP_PREDICATE;
15541554
}
15551555
}
1556-
} else {
1557-
ConstantExpr *CE2 = cast<ConstantExpr>(V2);
1558-
Constant *CE2Op0 = CE2->getOperand(0);
1559-
1560-
// There are MANY other foldings that we could perform here. They will
1561-
// probably be added on demand, as they seem needed.
1562-
switch (CE2->getOpcode()) {
1563-
default: break;
1564-
case Instruction::GetElementPtr:
1565-
// By far the most common case to handle is when the base pointers are
1566-
// obviously to the same global.
1567-
if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1568-
// Don't know relative ordering, but check for inequality.
1569-
if (CE1Op0 != CE2Op0) {
1570-
GEPOperator *CE2GEP = cast<GEPOperator>(CE2);
1571-
if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices())
1572-
return areGlobalsPotentiallyEqual(cast<GlobalValue>(CE1Op0),
1573-
cast<GlobalValue>(CE2Op0));
1574-
return ICmpInst::BAD_ICMP_PREDICATE;
1575-
}
1556+
} else if (const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) {
1557+
// By far the most common case to handle is when the base pointers are
1558+
// obviously to the same global.
1559+
const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand());
1560+
if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1561+
// Don't know relative ordering, but check for inequality.
1562+
if (CE1Op0 != CE2Op0) {
1563+
if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices())
1564+
return areGlobalsPotentiallyEqual(cast<GlobalValue>(CE1Op0),
1565+
cast<GlobalValue>(CE2Op0));
1566+
return ICmpInst::BAD_ICMP_PREDICATE;
15761567
}
15771568
}
15781569
}

0 commit comments

Comments
 (0)