diff options
author | Philip Reames <listmail@philipreames.com> | 2019-06-11 22:43:25 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-06-11 22:43:25 +0000 |
commit | 082cd30327dbc37bcdf6aba48f06048e63f12ae0 (patch) | |
tree | d22334d6078b5bb590b854840d7095f9f913d3b1 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | c06943b67d144124ef2a6027bf95c13c5bc18154 (diff) | |
download | llvm-082cd30327dbc37bcdf6aba48f06048e63f12ae0.zip llvm-082cd30327dbc37bcdf6aba48f06048e63f12ae0.tar.gz llvm-082cd30327dbc37bcdf6aba48f06048e63f12ae0.tar.bz2 |
Generalize icmp matching in IndVars' eliminateTrunc
We were only matching RHS being a loop invariant value, not the inverse. Since there's nothing which appears to canonicalize loop invariant values to RHS, this means we missed cases.
Differential Revision: https://reviews.llvm.org/D63112
llvm-svn: 363108
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 9a4ebd3..f1048d9 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -521,20 +521,19 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) { if (isa<Instruction>(U) && !DT->isReachableFromEntry(cast<Instruction>(U)->getParent())) continue; - if (ICmpInst *ICI = dyn_cast<ICmpInst>(U)) { - if (ICI->getOperand(0) == TI && L->isLoopInvariant(ICI->getOperand(1))) { - assert(L->contains(ICI->getParent()) && "LCSSA form broken?"); - // If we cannot get rid of trunc, bail. - if (ICI->isSigned() && !DoesSExtCollapse) - return false; - if (ICI->isUnsigned() && !DoesZExtCollapse) - return false; - // For equality, either signed or unsigned works. - ICmpUsers.push_back(ICI); - } else - return false; - } else + ICmpInst *ICI = dyn_cast<ICmpInst>(U); + if (!ICI) return false; + assert(L->contains(ICI->getParent()) && "LCSSA form broken?"); + if (!(ICI->getOperand(0) == TI && L->isLoopInvariant(ICI->getOperand(1))) && + !(ICI->getOperand(1) == TI && L->isLoopInvariant(ICI->getOperand(0)))) return false; + // If we cannot get rid of trunc, bail. + if (ICI->isSigned() && !DoesSExtCollapse) + return false; + if (ICI->isUnsigned() && !DoesZExtCollapse) + return false; + // For equality, either signed or unsigned works. + ICmpUsers.push_back(ICI); } auto CanUseZExt = [&](ICmpInst *ICI) { @@ -557,7 +556,8 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) { }; // Replace all comparisons against trunc with comparisons against IV. for (auto *ICI : ICmpUsers) { - auto *Op1 = ICI->getOperand(1); + bool IsSwapped = L->isLoopInvariant(ICI->getOperand(0)); + auto *Op1 = IsSwapped ? ICI->getOperand(0) : ICI->getOperand(1); Instruction *Ext = nullptr; // For signed/unsigned predicate, replace the old comparison with comparison // of immediate IV against sext/zext of the invariant argument. If we can @@ -566,6 +566,7 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) { // TODO: If we see a signed comparison which can be turned into unsigned, // we can do it here for canonicalization purposes. ICmpInst::Predicate Pred = ICI->getPredicate(); + if (IsSwapped) Pred = ICmpInst::getSwappedPredicate(Pred); if (CanUseZExt(ICI)) { assert(DoesZExtCollapse && "Unprofitable zext?"); Ext = new ZExtInst(Op1, IVTy, "zext", ICI); |