llvm.org GIT mirror llvm / d5a3ed4
[IndVars, RLEV] Support rewriting exit values in loops without known exits (prep work) This is a prepatory patch for future work on support exit value rewriting in loops with a mixture of computable and non-computable exit counts. The intention is to be "mostly NFC" - i.e. not enable any interesting new transforms - but in practice, there are some small output changes. The test differences are caused by cases wherewhere getSCEVAtScope can simplify a single entry phi without needing any knowledge of the loop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367485 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames a month ago
3 changed file(s) with 9 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
629629 // and varies predictably *inside* the loop. Evaluate the value it
630630 // contains when the loop exits, if possible.
631631 const SCEV *ExitValue = SE->getSCEVAtScope(Inst, L->getParentLoop());
632 if (!SE->isLoopInvariant(ExitValue, L) ||
632 if (isa(ExitValue) ||
633 !SE->isLoopInvariant(ExitValue, L) ||
633634 !isSafeToExpand(ExitValue, *SE))
634635 continue;
635636
803804 L->getExitingBlocks(ExitingBlocks);
804805 SmallVector ExitBlocks;
805806 L->getUniqueExitBlocks(ExitBlocks);
806 if (ExitBlocks.size() > 1 || ExitingBlocks.size() > 1)
807 if (ExitBlocks.size() != 1 || ExitingBlocks.size() != 1)
807808 return false;
808809
809810 BasicBlock *ExitBlock = ExitBlocks[0];
27732774 Rewriter.disableCanonicalMode();
27742775 Changed |= simplifyAndExtend(L, Rewriter, LI);
27752776
2776 // Check to see if this loop has a computable loop-invariant execution count.
2777 // If so, this means that we can compute the final value of any expressions
2777 // Check to see if we can compute the final value of any expressions
27782778 // that are recurrent in the loop, and substitute the exit values from the
2779 // loop into any instructions outside of the loop that use the final values of
2780 // the current expressions.
2781 //
2782 if (ReplaceExitValue != NeverRepl &&
2783 !isa(BackedgeTakenCount))
2779 // loop into any instructions outside of the loop that use the final values
2780 // of the current expressions.
2781 if (ReplaceExitValue != NeverRepl)
27842782 Changed |= rewriteLoopExitValues(L, Rewriter);
27852783
27862784 // Eliminate redundant IV cycles.
6161 ; CHECK: cond.false.us:
6262 ; CHECK-NEXT: br label [[COND_END_US]]
6363 ; CHECK: cond.end.us:
64 ; CHECK-NEXT: [[COND_US:%.*]] = phi i32 [ [[DIV]], [[COND_FALSE_US]] ], [ [[INDVARS_IV]], [[FOR_BODY3_US]] ]
6564 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* @b, align 4
6665 ; CHECK-NEXT: [[CMP91_US:%.*]] = icmp slt i32 [[TMP6]], 1
6766 ; CHECK-NEXT: br i1 [[CMP91_US]], label [[FOR_INC_LR_PH_US:%.*]], label [[FOR_COND2_LOOPEXIT_US:%.*]]
7877 ; CHECK-NEXT: store i32 1, i32* @b, align 4
7978 ; CHECK-NEXT: br label [[FOR_COND2_LOOPEXIT_US]]
8079 ; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us.us-lcssa:
81 ; CHECK-NEXT: [[COND_LCSSA_PH_US_PH:%.*]] = phi i32 [ [[COND_US]], [[FOR_COND2_LOOPEXIT_US]] ]
8280 ; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US]]
8381 ; CHECK: for.cond2.for.inc13_crit_edge.us-lcssa.us:
84 ; CHECK-NEXT: [[COND_LCSSA_PH_US:%.*]] = phi i32 [ [[COND_LCSSA_PH_US_PH]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA]] ], [ [[DIV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA_US]] ]
82 ; CHECK-NEXT: [[COND_LCSSA_PH_US:%.*]] = phi i32 [ [[DIV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA]] ], [ [[DIV]], [[FOR_COND2_FOR_INC13_CRIT_EDGE_US_LCSSA_US_US_LCSSA_US]] ]
8583 ; CHECK-NEXT: br label [[FOR_COND2_FOR_INC13_CRIT_EDGE:%.*]]
8684 ; CHECK: for.body3.lr.ph.split:
8785 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[FOR_BODY3_LR_PH_SPLIT_SPLIT_US:%.*]], label [[FOR_BODY3_LR_PH_SPLIT_FOR_BODY3_LR_PH_SPLIT_SPLIT_CRIT_EDGE:%.*]]
9191 ; CHECK: for.end:
9292 ; CHECK-NEXT: br i1 false, label [[FOR_COND4_PREHEADER]], label [[FOR_END9:%.*]]
9393 ; CHECK: for.end9:
94 ; CHECK-NEXT: [[INC11:%.*]] = add nuw nsw i32 0, [[X]]
9594 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_PREHEADER]], label [[RETURN_LOOPEXIT3:%.*]]
9695 ; CHECK: return.loopexit:
9796 ; CHECK-NEXT: unreachable
9897 ; CHECK: return.loopexit3:
99 ; CHECK-NEXT: [[INC11_LCSSA:%.*]] = phi i32 [ [[INC11]], [[FOR_END9]] ]
10098 ; CHECK-NEXT: br label [[RETURN:%.*]]
10199 ; CHECK: return:
102 ; CHECK-NEXT: ret i32 [[INC11_LCSSA]]
100 ; CHECK-NEXT: ret i32 [[X]]
103101 ;
104102 entry:
105103 br label %for.cond1.preheader