Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ STATISTIC(
STATISTIC(
NumSimplifiedSRem,
"Number of IV signed remainder operations converted to unsigned remainder");
STATISTIC(NumElimCmp , "Number of IV comparisons eliminated");
STATISTIC(NumElimCmp, "Number of IV comparisons eliminated");
STATISTIC(NumInvariantCmp, "Number of IV comparisons made loop invariant");
STATISTIC(NumSameSign, "Number of IV comparisons with new samesign flags");

namespace {
/// This is a utility for simplifying induction variables
Expand Down Expand Up @@ -275,11 +277,20 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
ICmp->replaceAllUsesWith(ConstantInt::getBool(ICmp->getContext(), *Ev));
DeadInsts.emplace_back(ICmp);
LLVM_DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');
} else if (makeIVComparisonInvariant(ICmp, IVOperand)) {
// fallthrough to end of function
} else if ((ICmpInst::isSigned(OriginalPred) ||
(ICmpInst::isUnsigned(OriginalPred) && !ICmp->hasSameSign())) &&
SE->haveSameSign(S, X)) {
++NumElimCmp;
Changed = true;
return;
}

if (makeIVComparisonInvariant(ICmp, IVOperand)) {
++NumInvariantCmp;
Changed = true;
return;
}

if ((ICmpInst::isSigned(OriginalPred) ||
(ICmpInst::isUnsigned(OriginalPred) && !ICmp->hasSameSign())) &&
SE->haveSameSign(S, X)) {
// Set the samesign flag on the compare if legal, and canonicalize to
// the unsigned variant (for signed compares) hoping that it will open
// the doors for other optimizations. Note that we cannot rely on Pred
Expand All @@ -289,11 +300,10 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
<< '\n');
ICmp->setPredicate(ICmpInst::getUnsignedPredicate(OriginalPred));
ICmp->setSameSign();
} else
NumSameSign++;
Changed = true;
return;

++NumElimCmp;
Changed = true;
}
}

bool SimplifyIndvar::eliminateSDiv(BinaryOperator *SDiv) {
Expand Down