diff options
author | Nikita Popov <npopov@redhat.com> | 2022-01-04 12:33:38 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-01-04 12:33:38 +0100 |
commit | 1379eb577607dc7a070272e02bcb6712cbb8feed (patch) | |
tree | e4a895d66efb17251975e0da7bfa87eaf016b033 | |
parent | 75db002725156fba9e9c38b7cefe57b7ed713734 (diff) | |
download | llvm-1379eb577607dc7a070272e02bcb6712cbb8feed.tar.gz |
[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.
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 31 |
1 files 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<ConstantExpr>(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<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) { - // Don't know relative ordering, but check for inequality. - if (CE1Op0 != CE2Op0) { - GEPOperator *CE2GEP = cast<GEPOperator>(CE2); - if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices()) - return areGlobalsPotentiallyEqual(cast<GlobalValue>(CE1Op0), - cast<GlobalValue>(CE2Op0)); - return ICmpInst::BAD_ICMP_PREDICATE; - } + } else if (const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) { + // By far the most common case to handle is when the base pointers are + // obviously to the same global. + const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand()); + if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) { + // Don't know relative ordering, but check for inequality. + if (CE1Op0 != CE2Op0) { + if (CE1GEP->hasAllZeroIndices() && CE2GEP->hasAllZeroIndices()) + return areGlobalsPotentiallyEqual(cast<GlobalValue>(CE1Op0), + cast<GlobalValue>(CE2Op0)); + return ICmpInst::BAD_ICMP_PREDICATE; } } } |