diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-10-12 23:23:22 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-10-14 21:52:31 +0200 |
commit | 69853f992048efa7fd1b2700b7b71def72300682 (patch) | |
tree | 209e111b939267bc32ac04109e220fc84abf4821 /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | |
parent | 68157fe15b238428d0fdbeb38c14afd5bda574da (diff) | |
download | llvm-69853f992048efa7fd1b2700b7b71def72300682.zip llvm-69853f992048efa7fd1b2700b7b71def72300682.tar.gz llvm-69853f992048efa7fd1b2700b7b71def72300682.tar.bz2 |
[IVUsers] Move preheader check into SCEVExpander
Rather than checking for loop nest preheaders upfront in IVUsers,
move this requirement into isSafeToExpand() from SCEVExpander.
Historically, LSR did not check whether SCEVs are safe to expand
and fully relied on IVUsers to validate this. Later, support for
non-expandable SCEVs was added via rigid formulas.
Checking this in isSafeToExpand() makes it more obvious what
exactly this check is guarding against, and avoids the awkward
loop nest scan.
This is a followup to https://reviews.llvm.org/D111493#3055286.
Differential Revision: https://reviews.llvm.org/D111681
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index e8277f8..a25f9d6 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -2618,9 +2618,11 @@ namespace { // perfectly reduced form, which can't be guaranteed. struct SCEVFindUnsafe { ScalarEvolution &SE; + bool CanonicalMode; bool IsUnsafe; - SCEVFindUnsafe(ScalarEvolution &se): SE(se), IsUnsafe(false) {} + SCEVFindUnsafe(ScalarEvolution &SE, bool CanonicalMode) + : SE(SE), CanonicalMode(CanonicalMode), IsUnsafe(false) {} bool follow(const SCEV *S) { if (const SCEVUDivExpr *D = dyn_cast<SCEVUDivExpr>(S)) { @@ -2636,6 +2638,14 @@ struct SCEVFindUnsafe { IsUnsafe = true; return false; } + + // For non-affine addrecs or in non-canonical mode we need a preheader + // to insert into. + if (!AR->getLoop()->getLoopPreheader() && + (!CanonicalMode || !AR->isAffine())) { + IsUnsafe = true; + return false; + } } return true; } @@ -2644,8 +2654,8 @@ struct SCEVFindUnsafe { } namespace llvm { -bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE) { - SCEVFindUnsafe Search(SE); +bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE, bool CanonicalMode) { + SCEVFindUnsafe Search(SE, CanonicalMode); visitAll(S, Search); return !Search.IsUnsafe; } |