@@ -43,7 +43,9 @@ STATISTIC(
4343STATISTIC (
4444 NumSimplifiedSRem,
4545 " Number of IV signed remainder operations converted to unsigned remainder" );
46- STATISTIC (NumElimCmp , " Number of IV comparisons eliminated" );
46+ STATISTIC (NumElimCmp, " Number of IV comparisons eliminated" );
47+ STATISTIC (NumInvariantCmp, " Number of IV comparisons made loop invariant" );
48+ STATISTIC (NumSameSign, " Number of IV comparisons with new samesign flags" );
4749
4850namespace {
4951 // / This is a utility for simplifying induction variables
@@ -275,11 +277,20 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
275277 ICmp->replaceAllUsesWith (ConstantInt::getBool (ICmp->getContext (), *Ev));
276278 DeadInsts.emplace_back (ICmp);
277279 LLVM_DEBUG (dbgs () << " INDVARS: Eliminated comparison: " << *ICmp << ' \n ' );
278- } else if (makeIVComparisonInvariant (ICmp, IVOperand)) {
279- // fallthrough to end of function
280- } else if ((ICmpInst::isSigned (OriginalPred) ||
281- (ICmpInst::isUnsigned (OriginalPred) && !ICmp->hasSameSign ())) &&
282- SE->haveSameSign (S, X)) {
280+ ++NumElimCmp;
281+ Changed = true ;
282+ return ;
283+ }
284+
285+ if (makeIVComparisonInvariant (ICmp, IVOperand)) {
286+ ++NumInvariantCmp;
287+ Changed = true ;
288+ return ;
289+ }
290+
291+ if ((ICmpInst::isSigned (OriginalPred) ||
292+ (ICmpInst::isUnsigned (OriginalPred) && !ICmp->hasSameSign ())) &&
293+ SE->haveSameSign (S, X)) {
283294 // Set the samesign flag on the compare if legal, and canonicalize to
284295 // the unsigned variant (for signed compares) hoping that it will open
285296 // the doors for other optimizations. Note that we cannot rely on Pred
@@ -289,11 +300,10 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp,
289300 << ' \n ' );
290301 ICmp->setPredicate (ICmpInst::getUnsignedPredicate (OriginalPred));
291302 ICmp->setSameSign ();
292- } else
303+ NumSameSign++;
304+ Changed = true ;
293305 return ;
294-
295- ++NumElimCmp;
296- Changed = true ;
306+ }
297307}
298308
299309bool SimplifyIndvar::eliminateSDiv (BinaryOperator *SDiv) {
0 commit comments