llvm.org GIT mirror llvm / f21bdf4
Rename -disable-iv-rewrite to -enable-iv-rewrite=false in preparation for default change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139517 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
11 changed file(s) with 30 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
1010 // computations derived from them) into simpler forms suitable for subsequent
1111 // analysis and transformation.
1212 //
13 // Additionally, unless -disable-iv-rewrite is on, this transformation makes the
14 // following changes to each loop with an identifiable induction variable:
15 // 1. All loops are transformed to have a SINGLE canonical induction variable
16 // which starts at zero and steps by one.
17 // 2. The canonical induction variable is guaranteed to be the first PHI node
18 // in the loop header block.
19 // 3. The canonical induction variable is guaranteed to be in a wide enough
20 // type so that IV expressions need not be (directly) zero-extended or
21 // sign-extended.
22 // 4. Any pointer arithmetic recurrences are raised to use array subscripts.
23 //
2413 // If the trip count of a loop is computable, this pass also makes the following
2514 // changes:
2615 // 1. The exit condition for the loop is canonicalized to compare the
3120 // the dependence on the exit value of the induction variable. If the only
3221 // purpose of the loop is to compute the exit value of some derived
3322 // expression, this transformation will make the loop dead.
34 //
35 // This transformation should be followed by strength reduction after all of the
36 // desired loop transformations have been performed.
3723 //
3824 //===----------------------------------------------------------------------===//
3925
7258 STATISTIC(NumElimIV , "Number of congruent IVs eliminated");
7359
7460 namespace llvm {
75 cl::opt DisableIVRewrite(
76 "disable-iv-rewrite", cl::Hidden,
77 cl::desc("Disable canonical induction variable rewriting"));
61 cl::opt EnableIVRewrite(
62 "enable-iv-rewrite", cl::Hidden, cl::init(true),
63 cl::desc("Enable canonical induction variable rewriting"));
7864
7965 // Trip count verification can be enabled by default under NDEBUG if we
8066 // implement a strong expression equivalence checker in SCEV. Until then, we
8369 "verify-indvars", cl::Hidden,
8470 cl::desc("Verify the ScalarEvolution result after running indvars"));
8571 }
86
87 // Temporary flag for use with -disable-iv-rewrite to force a canonical IV for
88 // LFTR purposes.
89 static cl::opt ForceLFTR(
90 "force-lftr", cl::Hidden,
91 cl::desc("Enable forced linear function test replacement"));
9272
9373 namespace {
9474 class IndVarSimplify : public LoopPass {
11696 AU.addRequired();
11797 AU.addRequiredID(LoopSimplifyID);
11898 AU.addRequiredID(LCSSAID);
119 if (!DisableIVRewrite)
99 if (EnableIVRewrite)
120100 AU.addRequired();
121101 AU.addPreserved();
122102 AU.addPreservedID(LoopSimplifyID);
123103 AU.addPreservedID(LCSSAID);
124 if (!DisableIVRewrite)
104 if (EnableIVRewrite)
125105 AU.addPreserved();
126106 AU.setPreservesCFG();
127107 }
617597
618598 //===----------------------------------------------------------------------===//
619599 // Rewrite IV users based on a canonical IV.
620 // To be replaced by -disable-iv-rewrite.
600 // Only for use with -enable-iv-rewrite.
621601 //===----------------------------------------------------------------------===//
622602
623603 /// FIXME: It is an extremely bad idea to indvar substitute anything more
13321312 }
13331313 }
13341314
1335 if (!DisableIVRewrite || ForceLFTR)
1315 if (EnableIVRewrite)
13361316 return false;
13371317
13381318 // Recurse past add expressions, which commonly occur in the
16091589 assert(canExpandBackedgeTakenCount(L, SE) && "precondition");
16101590 BranchInst *BI = cast(L->getExitingBlock()->getTerminator());
16111591
1612 // In DisableIVRewrite mode, IndVar is not necessarily a canonical IV. In this
1613 // mode, LFTR can ignore IV overflow and truncate to the width of
1592 // LFTR can ignore IV overflow and truncate to the width of
16141593 // BECount. This avoids materializing the add(zext(add)) expression.
1615 Type *CntTy = DisableIVRewrite ?
1594 Type *CntTy = !EnableIVRewrite ?
16161595 BackedgeTakenCount->getType() : IndVar->getType();
16171596
16181597 const SCEV *IVLimit = BackedgeTakenCount;
16621641 const SCEV *IVInit = AR->getStart();
16631642
16641643 // For pointer types, sign extend BECount in order to materialize a GEP.
1665 // Note that for DisableIVRewrite, we never run SCEVExpander on a
1644 // Note that for without EnableIVRewrite, we never run SCEVExpander on a
16661645 // pointer type, because we must preserve the existing GEPs. Instead we
16671646 // directly generate a GEP later.
16681647 if (IVInit->getType()->isPointerTy()) {
18401819 if (!L->isLoopSimplifyForm())
18411820 return false;
18421821
1843 if (!DisableIVRewrite)
1822 if (EnableIVRewrite)
18441823 IU = &getAnalysis();
18451824 LI = &getAnalysis();
18461825 SE = &getAnalysis();
18651844 // attempt to avoid evaluating SCEVs for sign/zero extend operations until
18661845 // other expressions involving loop IVs have been evaluated. This helps SCEV
18671846 // set no-wrap flags before normalizing sign/zero extension.
1868 if (DisableIVRewrite) {
1847 if (!EnableIVRewrite) {
18691848 Rewriter.disableCanonicalMode();
18701849 SimplifyAndExtend(L, Rewriter, LPM);
18711850 }
18801859 RewriteLoopExitValues(L, Rewriter);
18811860
18821861 // Eliminate redundant IV users.
1883 if (!DisableIVRewrite)
1862 if (EnableIVRewrite)
18841863 Changed |= simplifyIVUsers(IU, SE, &LPM, DeadInsts);
18851864
18861865 // Eliminate redundant IV cycles.
1887 if (DisableIVRewrite)
1866 if (!EnableIVRewrite)
18881867 SimplifyCongruentIVs(L);
18891868
18901869 // Compute the type of the largest recurrence expression, and decide whether
18911870 // a canonical induction variable should be inserted.
18921871 Type *LargestType = 0;
18931872 bool NeedCannIV = false;
1894 bool ReuseIVForExit = DisableIVRewrite && !ForceLFTR;
18951873 bool ExpandBECount = canExpandBackedgeTakenCount(L, SE);
1896 if (ExpandBECount && !ReuseIVForExit) {
1874 if (EnableIVRewrite && ExpandBECount) {
18971875 // If we have a known trip count and a single exit block, we'll be
18981876 // rewriting the loop exit test condition below, which requires a
18991877 // canonical induction variable.
19001878 NeedCannIV = true;
19011879 Type *Ty = BackedgeTakenCount->getType();
1902 if (DisableIVRewrite) {
1880 if (!EnableIVRewrite) {
19031881 // In this mode, SimplifyIVUsers may have already widened the IV used by
19041882 // the backedge test and inserted a Trunc on the compare's operand. Get
19051883 // the wider type to avoid creating a redundant narrow IV only used by the
19111889 SE->getTypeSizeInBits(LargestType))
19121890 LargestType = SE->getEffectiveSCEVType(Ty);
19131891 }
1914 if (!DisableIVRewrite) {
1892 if (EnableIVRewrite) {
19151893 for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
19161894 NeedCannIV = true;
19171895 Type *Ty =
19561934 OldCannIV->insertBefore(L->getHeader()->getFirstInsertionPt());
19571935 }
19581936 }
1959 else if (ExpandBECount && ReuseIVForExit && needsLFTR(L, DT)) {
1937 else if (!EnableIVRewrite && ExpandBECount && needsLFTR(L, DT)) {
19601938 IndVar = FindLoopCounter(L, BackedgeTakenCount, SE, DT, TD);
19611939 }
19621940 // If we have a trip count expression, rewrite the loop's exit condition
19771955 LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar, Rewriter);
19781956 }
19791957 // Rewrite IV-derived expressions.
1980 if (!DisableIVRewrite)
1958 if (EnableIVRewrite)
19811959 RewriteIVExpressions(L, Rewriter);
19821960
19831961 // Clear the rewriter cache, because values that are in the rewriter's cache
20141992 // Verify that LFTR, and any other change have not interfered with SCEV's
20151993 // ability to compute trip count.
20161994 #ifndef NDEBUG
2017 if (DisableIVRewrite && VerifyIndvars &&
1995 if (!EnableIVRewrite && VerifyIndvars &&
20181996 !isa(BackedgeTakenCount)) {
20191997 SE->forgetLoop(L);
20201998 const SCEV *NewBECount = SE->getBackedgeTakenCount(L);
None ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
0 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
11 ; Test WidenIV::GetExtendedOperandRecurrence.
22 ; add219 should be extended to i64 because it is nsw, even though its
33 ; sext cannot be hoisted outside the loop.
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1 ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
1 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
22 ;
33 ; PR1301
44
None ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
0 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
11
22 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
33
None ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
0 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
11
22 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n:32:64"
33
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1 ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
1 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
22 ; CHECK-NOT: and
33 ; CHECK-NOT: zext
44
None ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
0 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
11 ;
22 ; Make sure that indvars can perform LFTR without a canonical IV.
33
None ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
0 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
11 ;
22 ; Make sure that indvars isn't inserting canonical IVs.
33 ; This is kinda hard to do until linear function test replacement is removed.
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1 ; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
1 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s
22
33 ; Indvars should insert a 64-bit induction variable to eliminate the
44 ; sext for the addressing, however it shouldn't eliminate the sext
0 ; RUN: opt < %s -indvars -instcombine -S | FileCheck %s
1 ; RUN: opt < %s -indvars -disable-iv-rewrite -instcombine -S | FileCheck %s
1 ; RUN: opt < %s -indvars -enable-iv-rewrite=false -instcombine -S | FileCheck %s
22 ;
33 ; Test that -indvars can reduce variable stride IVs. If it can reduce variable
44 ; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
None ; RUN: opt -S < %s -loop-unroll -unroll-count=4 -disable-iv-rewrite | FileCheck %s
0 ; RUN: opt -S < %s -loop-unroll -unroll-count=4 -enable-iv-rewrite=false | FileCheck %s
11 ;
22 ; Test induction variable simplify after loop unrolling. It should
33 ; expose nice opportunities for GVN.