diff options
author | Eli Friedman <efriedma@quicinc.com> | 2021-06-23 14:43:59 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2021-07-09 17:29:26 -0700 |
commit | 9c4baf5101e9ee55bfae1ce7657a7b89a06b4ccf (patch) | |
tree | 8420f031ad3ba4cda014c61a6b9b20ab0481d94d /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | |
parent | 8e9216fe877cf263c93a0f769235bef425d395b6 (diff) | |
download | llvm-9c4baf5101e9ee55bfae1ce7657a7b89a06b4ccf.zip llvm-9c4baf5101e9ee55bfae1ce7657a7b89a06b4ccf.tar.gz llvm-9c4baf5101e9ee55bfae1ce7657a7b89a06b4ccf.tar.bz2 |
[ScalarEvolution] Strictly enforce pointer/int type rules.
Rules:
1. SCEVUnknown is a pointer if and only if the LLVM IR value is a
pointer.
2. SCEVPtrToInt is never a pointer.
3. If any other SCEV expression has no pointer operands, the result is
an integer.
4. If a SCEVAddExpr has exactly one pointer operand, the result is a
pointer.
5. If a SCEVAddRecExpr's first operand is a pointer, and it has no other
pointer operands, the result is a pointer.
6. If every operand of a SCEVMinMaxExpr is a pointer, the result is a
pointer.
7. Otherwise, the SCEV expression is invalid.
I'm not sure how useful rule 6 is in practice. If we exclude it, we can
guarantee that ScalarEvolution::getPointerBase always returns a
SCEVUnknown, which might be a helpful property. Anyway, I'll leave that
for a followup.
This is basically mop-up at this point; all the changes with significant
functional effects have landed. Some of the remaining changes could be
split off, but I don't see much point.
Differential Revision: https://reviews.llvm.org/D105510
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 1cf3f97..5af1c37 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1147,6 +1147,10 @@ static bool canBeCheaplyTransformed(ScalarEvolution &SE, const SCEVAddRecExpr *Phi, const SCEVAddRecExpr *Requested, bool &InvertStep) { + // We can't transform to match a pointer PHI. + if (Phi->getType()->isPointerTy()) + return false; + Type *PhiTy = SE.getEffectiveSCEVType(Phi->getType()); Type *RequestedTy = SE.getEffectiveSCEVType(Requested->getType()); @@ -1165,8 +1169,7 @@ static bool canBeCheaplyTransformed(ScalarEvolution &SE, } // Check whether inverting will help: {R,+,-1} == R - {0,+,1}. - if (SE.getAddExpr(Requested->getStart(), - SE.getNegativeSCEV(Requested)) == Phi) { + if (SE.getMinusSCEV(Requested->getStart(), Requested) == Phi) { InvertStep = true; return true; } @@ -1577,8 +1580,8 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { // Rewrite an AddRec in terms of the canonical induction variable, if // its type is more narrow. if (CanonicalIV && - SE.getTypeSizeInBits(CanonicalIV->getType()) > - SE.getTypeSizeInBits(Ty)) { + SE.getTypeSizeInBits(CanonicalIV->getType()) > SE.getTypeSizeInBits(Ty) && + !S->getType()->isPointerTy()) { SmallVector<const SCEV *, 4> NewOps(S->getNumOperands()); for (unsigned i = 0, e = S->getNumOperands(); i != e; ++i) NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType()); |