Skip to content

Commit 815aa31

Browse files
committed
step
1 parent a4015d9 commit 815aa31

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15565,6 +15565,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1556515565
assert(SE.DT.isReachableFromEntry(Block) && SE.DT.isReachableFromEntry(Pred));
1556615566

1556715567
SmallVector<const SCEV *> ExprsToRewrite;
15568+
DenseMap<const SCEV *, const SCEV *> DivInfo;
1556815569
auto CollectCondition = [&](ICmpInst::Predicate Predicate, const SCEV *LHS,
1556915570
const SCEV *RHS,
1557015571
DenseMap<const SCEV *, const SCEV *>
@@ -15715,6 +15716,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1571515716
const auto *Multiple =
1571615717
SE.getMulExpr(SE.getUDivExpr(RewrittenLHS, URemRHS), URemRHS);
1571715718
RewriteMap[LHSUnknown] = Multiple;
15719+
DivInfo[LHSUnknown] = Multiple;
1571815720
ExprsToRewrite.push_back(LHSUnknown);
1571915721
return;
1572015722
}
@@ -15746,12 +15748,23 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1574615748
// existing rewrite because we want to chain further rewrites onto the
1574715749
// already rewritten value. Otherwise returns \p S.
1574815750
auto GetMaybeRewritten = [&](const SCEV *S) {
15749-
return RewriteMap.lookup_or(S, S);
15751+
if (auto *N = RewriteMap.lookup(S))
15752+
return N;
15753+
LoopGuards Guards(SE);
15754+
Guards.RewriteMap = DivInfo;
15755+
return Guards.rewrite(S);
1575015756
};
1575115757

15758+
auto GetMaybeRewrittenDivInfo = [&](const SCEV *S) {
15759+
LoopGuards Guards(SE);
15760+
Guards.RewriteMap = DivInfo;
15761+
return Guards.rewrite(S);
15762+
};
15763+
15764+
1575215765
const SCEV *RewrittenLHS = GetMaybeRewritten(LHS);
1575315766
const SCEV *DividesBy = nullptr;
15754-
const APInt &Multiple = SE.getConstantMultiple(RewrittenLHS);
15767+
const APInt &Multiple = SE.getConstantMultiple(GetMaybeRewrittenDivInfo(RewrittenLHS));
1575515768
if (!Multiple.isOne())
1575615769
DividesBy = SE.getConstant(Multiple);
1575715770

0 commit comments

Comments
 (0)