diff options
author | Nikita Popov <npopov@redhat.com> | 2022-02-25 10:09:16 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-02-25 10:09:16 +0100 |
commit | 16a2d5f885529f94d7ccd6aaf3b087fa4cb59b5c (patch) | |
tree | a7beceb5ea37fab49b95e1de9494526bd10041b0 /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | |
parent | 87ebd9a36ffb547c18bb3acce2fa90f56d6c5d9d (diff) | |
download | llvm-16a2d5f885529f94d7ccd6aaf3b087fa4cb59b5c.zip llvm-16a2d5f885529f94d7ccd6aaf3b087fa4cb59b5c.tar.gz llvm-16a2d5f885529f94d7ccd6aaf3b087fa4cb59b5c.tar.bz2 |
[SCEVExpander] Use early returns in FindValueInExprValueMap() (NFC)
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 327d15d..89dd5aad 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1872,28 +1872,29 @@ Value *SCEVExpander::expandCodeForImpl(const SCEV *SH, Type *Ty, bool Root) { Value *SCEVExpander::FindValueInExprValueMap(const SCEV *S, const Instruction *InsertPt) { - ArrayRef<Value *> Set = SE.getSCEVValues(S); // If the expansion is not in CanonicalMode, and the SCEV contains any // sub scAddRecExpr type SCEV, it is required to expand the SCEV literally. - if (CanonicalMode || !SE.containsAddRecurrence(S)) { - // If S is scConstant, it may be worse to reuse an existing Value. - if (S->getSCEVType() != scConstant) { - // Choose a Value from the set which dominates the InsertPt. - // InsertPt should be inside the Value's parent loop so as not to break - // the LCSSA form. - for (Value *V : Set) { - Instruction *EntInst = dyn_cast<Instruction>(V); - if (!EntInst) - continue; + if (!CanonicalMode && SE.containsAddRecurrence(S)) + return nullptr; - assert(EntInst->getFunction() == InsertPt->getFunction()); - if (S->getType() == V->getType() && - SE.DT.dominates(EntInst, InsertPt) && - (SE.LI.getLoopFor(EntInst->getParent()) == nullptr || - SE.LI.getLoopFor(EntInst->getParent())->contains(InsertPt))) - return V; - } - } + // If S is a constant, it may be worse to reuse an existing Value. + if (isa<SCEVConstant>(S)) + return nullptr; + + // Choose a Value from the set which dominates the InsertPt. + // InsertPt should be inside the Value's parent loop so as not to break + // the LCSSA form. + for (Value *V : SE.getSCEVValues(S)) { + Instruction *EntInst = dyn_cast<Instruction>(V); + if (!EntInst) + continue; + + assert(EntInst->getFunction() == InsertPt->getFunction()); + if (S->getType() == V->getType() && + SE.DT.dominates(EntInst, InsertPt) && + (SE.LI.getLoopFor(EntInst->getParent()) == nullptr || + SE.LI.getLoopFor(EntInst->getParent())->contains(InsertPt))) + return V; } return nullptr; } |