Skip to content

Commit 1dc4ea8

Browse files
committed
!fixup avoid copying map and add TODO
1 parent 887ac61 commit 1dc4ea8

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
@@ -15594,8 +15594,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1559415594
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
1559515595
const SCEV *RHS,
1559615596
DenseMap<const SCEV *, const SCEV *> &RewriteMap,
15597-
const DenseMap<const SCEV *, const SCEV *>
15598-
&DivInfo) {
15597+
const LoopGuards &DivGuards) {
1559915598
// WARNING: It is generally unsound to apply any wrap flags to the proposed
1560015599
// replacement SCEV which isn't directly implied by the structure of that
1560115600
// SCEV. In particular, using contextual facts to imply flags is *NOT*
@@ -15637,12 +15636,6 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1563715636
if (isa<SCEVConstant>(LHS) || SE.containsAddRecurrence(RHS))
1563815637
return;
1563915638

15640-
// If RHS is SCEVUnknown, make sure the information is applied to it.
15641-
if (!isa<SCEVUnknown>(LHS) && isa<SCEVUnknown>(RHS)) {
15642-
std::swap(LHS, RHS);
15643-
Predicate = CmpInst::getSwappedPredicate(Predicate);
15644-
}
15645-
1564615639
// Puts rewrite rule \p From -> \p To into the rewrite map. Also if \p From
1564715640
// and \p FromRewritten are the same (i.e. there has been no rewrite
1564815641
// registered for \p From), then puts this value in the list of rewritten
@@ -15663,8 +15656,6 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1566315656

1566415657
const SCEV *RewrittenLHS = GetMaybeRewritten(LHS);
1566515658
// Apply divisibility information when computing the constant multiple.
15666-
LoopGuards DivGuards(SE);
15667-
DivGuards.RewriteMap = DivInfo;
1566815659
const APInt &DividesBy =
1566915660
SE.getConstantMultiple(DivGuards.rewrite(RewrittenLHS));
1567015661

@@ -15871,6 +15862,8 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1587115862
const auto *LHS = SE.getSCEV(Cmp->getOperand(0));
1587215863
const auto *RHS = SE.getSCEV(Cmp->getOperand(1));
1587315864
// If LHS is a constant, apply information to the other expression.
15865+
// TODO: If LHS is not a constant, check if using CompareSCEVComplexity
15866+
// can improve results.
1587415867
if (isa<SCEVConstant>(LHS)) {
1587515868
std::swap(LHS, RHS);
1587615869
Predicate = CmpInst::getSwappedPredicate(Predicate);
@@ -15888,17 +15881,18 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1588815881
}
1588915882
}
1589015883

15891-
// Process divisibility guards in reverse order to populate DivInfo early.
15884+
// Process divisibility guards in reverse order to populate DivGuards early.
1589215885
DenseMap<const SCEV *, APInt> Multiples;
15893-
DenseMap<const SCEV *, const SCEV *> DivInfo;
15886+
LoopGuards DivGuards(SE);
1589415887
for (const auto &[Predicate, LHS, RHS] : GuardsToProcess) {
1589515888
if (!isDivisibilityGuard(LHS, RHS, SE))
1589615889
continue;
15897-
collectDivisibilityInformation(Predicate, LHS, RHS, DivInfo, Multiples, SE);
15890+
collectDivisibilityInformation(Predicate, LHS, RHS, DivGuards.RewriteMap,
15891+
Multiples, SE);
1589815892
}
1589915893

1590015894
for (const auto &[Predicate, LHS, RHS] : GuardsToProcess)
15901-
CollectCondition(Predicate, LHS, RHS, Guards.RewriteMap, DivInfo);
15895+
CollectCondition(Predicate, LHS, RHS, Guards.RewriteMap, DivGuards);
1590215896

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

0 commit comments

Comments
 (0)