Skip to content

Commit 477551f

Browse files
committed
[SCEVExpander] Minor cleanup in value reuse (NFC)
Use dyn_cast_or_null and convert one of the checks into an assertion. SCEV is a per-function analysis.
1 parent a81672b commit 477551f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,16 +1844,18 @@ SCEVExpander::FindValueInExprValueMap(const SCEV *S,
18441844
if (CanonicalMode || !SE.containsAddRecurrence(S)) {
18451845
// If S is scConstant, it may be worse to reuse an existing Value.
18461846
if (S->getSCEVType() != scConstant && Set) {
1847-
// Choose a Value from the set which dominates the insertPt.
1848-
// insertPt should be inside the Value's parent loop so as not to break
1847+
// Choose a Value from the set which dominates the InsertPt.
1848+
// InsertPt should be inside the Value's parent loop so as not to break
18491849
// the LCSSA form.
18501850
for (auto const &VOPair : *Set) {
18511851
Value *V = VOPair.first;
18521852
ConstantInt *Offset = VOPair.second;
1853-
Instruction *EntInst = nullptr;
1854-
if (V && isa<Instruction>(V) && (EntInst = cast<Instruction>(V)) &&
1855-
S->getType() == V->getType() &&
1856-
EntInst->getFunction() == InsertPt->getFunction() &&
1853+
Instruction *EntInst = dyn_cast_or_null<Instruction>(V);
1854+
if (!EntInst)
1855+
continue;
1856+
1857+
assert(EntInst->getFunction() == InsertPt->getFunction());
1858+
if (S->getType() == V->getType() &&
18571859
SE.DT.dominates(EntInst, InsertPt) &&
18581860
(SE.LI.getLoopFor(EntInst->getParent()) == nullptr ||
18591861
SE.LI.getLoopFor(EntInst->getParent())->contains(InsertPt)))

0 commit comments

Comments
 (0)