From 1379eb577607dc7a070272e02bcb6712cbb8feed Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 4 Jan 2022 12:33:38 +0100 Subject: [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. --- llvm/lib/IR/ConstantFold.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index f32d26ba0978..c9ee60d684f9 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1553,26 +1553,17 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, return ICmpInst::BAD_ICMP_PREDICATE; } } - } else { - ConstantExpr *CE2 = cast(V2); - Constant *CE2Op0 = CE2->getOperand(0); - - // There are MANY other foldings that we could perform here. They will - // probably be added on demand, as they seem needed. - switch (CE2->getOpcode()) { - default: break; - case Instruction::GetElementPtr: - // By far the most common case to handle is when the base pointers are - // obviously to the same global. - if (isa(CE1Op0) && isa(CE2Op0)) { - // Don't know relative ordering, but check for inequality. - if (CE1Op0 != CE2Op0) { - GEPOperator *CE2GEP = cast(CE2); - if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices()) - return areGlobalsPotentiallyEqual(cast(CE1Op0), - cast(CE2Op0)); - return ICmpInst::BAD_ICMP_PREDICATE; - } + } else if (const auto *CE2GEP = dyn_cast(V2)) { + // By far the most common case to handle is when the base pointers are + // obviously to the same global. + const Constant *CE2Op0 = cast(CE2GEP->getPointerOperand()); + if (isa(CE1Op0) && isa(CE2Op0)) { + // Don't know relative ordering, but check for inequality. + if (CE1Op0 != CE2Op0) { + if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices()) + return areGlobalsPotentiallyEqual(cast(CE1Op0), + cast(CE2Op0)); + return ICmpInst::BAD_ICMP_PREDICATE; } } } -- cgit v1.2.1