Skip to content

Commit 8605517

Browse files
committed
!fixup avoid copying map and add TODO
1 parent 71a77f4 commit 8605517

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15589,8 +15589,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1558915589
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
1559015590
const SCEV *RHS,
1559115591
DenseMap<const SCEV *, const SCEV *> &RewriteMap,
15592-
const DenseMap<const SCEV *, const SCEV *>
15593-
&DivInfo) {
15592+
const LoopGuards &DivGuards) {
1559415593
// WARNING: It is generally unsound to apply any wrap flags to the proposed
1559515594
// replacement SCEV which isn't directly implied by the structure of that
1559615595
// SCEV. In particular, using contextual facts to imply flags is *NOT*
@@ -15632,12 +15631,6 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1563215631
if (isa<SCEVConstant>(LHS) || SE.containsAddRecurrence(RHS))
1563315632
return;
1563415633

15635-
// If RHS is SCEVUnknown, make sure the information is applied to it.
15636-
if (!isa<SCEVUnknown>(LHS) && isa<SCEVUnknown>(RHS)) {
15637-
std::swap(LHS, RHS);
15638-
Predicate = CmpInst::getSwappedPredicate(Predicate);
15639-
}
15640-
1564115634
// Puts rewrite rule \p From -> \p To into the rewrite map. Also if \p From
1564215635
// and \p FromRewritten are the same (i.e. there has been no rewrite
1564315636
// registered for \p From), then puts this value in the list of rewritten
@@ -15658,8 +15651,6 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1565815651

1565915652
const SCEV *RewrittenLHS = GetMaybeRewritten(LHS);
1566015653
// Apply divisibility information when computing the constant multiple.
15661-
LoopGuards DivGuards(SE);
15662-
DivGuards.RewriteMap = DivInfo;
1566315654
const APInt &DividesBy =
1566415655
SE.getConstantMultiple(DivGuards.rewrite(RewrittenLHS));
1566515656

@@ -15866,6 +15857,8 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1586615857
const auto *LHS = SE.getSCEV(Cmp->getOperand(0));
1586715858
const auto *RHS = SE.getSCEV(Cmp->getOperand(1));
1586815859
// If LHS is a constant, apply information to the other expression.
15860+
// TODO: If LHS is not a constant, check if using CompareSCEVComplexity
15861+
// can improve results.
1586915862
if (isa<SCEVConstant>(LHS)) {
1587015863
std::swap(LHS, RHS);
1587115864
Predicate = CmpInst::getSwappedPredicate(Predicate);
@@ -15883,17 +15876,18 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1588315876
}
1588415877
}
1588515878

15886-
// Process divisibility guards in reverse order to populate DivInfo early.
15879+
// Process divisibility guards in reverse order to populate DivGuards early.
1588715880
DenseMap<const SCEV *, APInt> Multiples;
15888-
DenseMap<const SCEV *, const SCEV *> DivInfo;
15881+
LoopGuards DivGuards(SE);
1588915882
for (const auto &[Predicate, LHS, RHS] : GuardsToProcess) {
1589015883
if (!isDivisibilityGuard(LHS, RHS, SE))
1589115884
continue;
15892-
collectDivisibilityInformation(Predicate, LHS, RHS, DivInfo, Multiples, SE);
15885+
collectDivisibilityInformation(Predicate, LHS, RHS, DivGuards.RewriteMap,
15886+
Multiples, SE);
1589315887
}
1589415888

1589515889
for (const auto &[Predicate, LHS, RHS] : GuardsToProcess)
15896-
CollectCondition(Predicate, LHS, RHS, Guards.RewriteMap, DivInfo);
15890+
CollectCondition(Predicate, LHS, RHS, Guards.RewriteMap, DivGuards);
1589715891

1589815892
// Apply divisibility information last. This ensures it is applied to the
1589915893
// outermost expression after other rewrites for the given value.

0 commit comments

Comments
 (0)