From f21bdf4f429223bcd76bf0198295a7ddbe7a1fdf Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Mon, 12 Sep 2011 18:28:44 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 62 ++++++------------- .../IndVarSimplify/2011-09-10-widen-nsw.ll | 2 +- test/Transforms/IndVarSimplify/ada-loops.ll | 2 +- test/Transforms/IndVarSimplify/elim-extend.ll | 2 +- test/Transforms/IndVarSimplify/iv-fold.ll | 2 +- test/Transforms/IndVarSimplify/iv-zext.ll | 2 +- test/Transforms/IndVarSimplify/lftr-reuse.ll | 2 +- .../IndVarSimplify/no-iv-rewrite.ll | 2 +- .../IndVarSimplify/preserve-signed-wrap.ll | 2 +- .../IndVarSimplify/variable-stride-ivs-0.ll | 2 +- .../LoopUnroll/2011-08-09-IVSimplify.ll | 2 +- 11 files changed, 30 insertions(+), 52 deletions(-) diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index ab61424664e..3a4580e1007 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -11,17 +11,6 @@ // computations derived from them) into simpler forms suitable for subsequent // analysis and transformation. // -// Additionally, unless -disable-iv-rewrite is on, this transformation makes the -// following changes to each loop with an identifiable induction variable: -// 1. All loops are transformed to have a SINGLE canonical induction variable -// which starts at zero and steps by one. -// 2. The canonical induction variable is guaranteed to be the first PHI node -// in the loop header block. -// 3. The canonical induction variable is guaranteed to be in a wide enough -// type so that IV expressions need not be (directly) zero-extended or -// sign-extended. -// 4. Any pointer arithmetic recurrences are raised to use array subscripts. -// // If the trip count of a loop is computable, this pass also makes the following // changes: // 1. The exit condition for the loop is canonicalized to compare the @@ -33,9 +22,6 @@ // purpose of the loop is to compute the exit value of some derived // expression, this transformation will make the loop dead. // -// This transformation should be followed by strength reduction after all of the -// desired loop transformations have been performed. -// //===----------------------------------------------------------------------===// #define DEBUG_TYPE "indvars" @@ -73,9 +59,9 @@ STATISTIC(NumElimExt , "Number of IV sign/zero extends eliminated"); STATISTIC(NumElimIV , "Number of congruent IVs eliminated"); namespace llvm { - cl::opt DisableIVRewrite( - "disable-iv-rewrite", cl::Hidden, - cl::desc("Disable canonical induction variable rewriting")); + cl::opt EnableIVRewrite( + "enable-iv-rewrite", cl::Hidden, cl::init(true), + cl::desc("Enable canonical induction variable rewriting")); // Trip count verification can be enabled by default under NDEBUG if we // implement a strong expression equivalence checker in SCEV. Until then, we @@ -85,12 +71,6 @@ namespace llvm { cl::desc("Verify the ScalarEvolution result after running indvars")); } -// Temporary flag for use with -disable-iv-rewrite to force a canonical IV for -// LFTR purposes. -static cl::opt ForceLFTR( - "force-lftr", cl::Hidden, - cl::desc("Enable forced linear function test replacement")); - namespace { class IndVarSimplify : public LoopPass { IVUsers *IU; @@ -117,12 +97,12 @@ namespace { AU.addRequired(); AU.addRequiredID(LoopSimplifyID); AU.addRequiredID(LCSSAID); - if (!DisableIVRewrite) + if (EnableIVRewrite) AU.addRequired(); AU.addPreserved(); AU.addPreservedID(LoopSimplifyID); AU.addPreservedID(LCSSAID); - if (!DisableIVRewrite) + if (EnableIVRewrite) AU.addPreserved(); AU.setPreservesCFG(); } @@ -618,7 +598,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L, SCEVExpander &Rewriter) { //===----------------------------------------------------------------------===// // Rewrite IV users based on a canonical IV. -// To be replaced by -disable-iv-rewrite. +// Only for use with -enable-iv-rewrite. //===----------------------------------------------------------------------===// /// FIXME: It is an extremely bad idea to indvar substitute anything more @@ -1333,7 +1313,7 @@ static bool isHighCostExpansion(const SCEV *S, BranchInst *BI, } } - if (!DisableIVRewrite || ForceLFTR) + if (EnableIVRewrite) return false; // Recurse past add expressions, which commonly occur in the @@ -1610,10 +1590,9 @@ LinearFunctionTestReplace(Loop *L, assert(canExpandBackedgeTakenCount(L, SE) && "precondition"); BranchInst *BI = cast(L->getExitingBlock()->getTerminator()); - // In DisableIVRewrite mode, IndVar is not necessarily a canonical IV. In this - // mode, LFTR can ignore IV overflow and truncate to the width of + // LFTR can ignore IV overflow and truncate to the width of // BECount. This avoids materializing the add(zext(add)) expression. - Type *CntTy = DisableIVRewrite ? + Type *CntTy = !EnableIVRewrite ? BackedgeTakenCount->getType() : IndVar->getType(); const SCEV *IVLimit = BackedgeTakenCount; @@ -1663,7 +1642,7 @@ LinearFunctionTestReplace(Loop *L, const SCEV *IVInit = AR->getStart(); // For pointer types, sign extend BECount in order to materialize a GEP. - // Note that for DisableIVRewrite, we never run SCEVExpander on a + // Note that for without EnableIVRewrite, we never run SCEVExpander on a // pointer type, because we must preserve the existing GEPs. Instead we // directly generate a GEP later. if (IVInit->getType()->isPointerTy()) { @@ -1841,7 +1820,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { if (!L->isLoopSimplifyForm()) return false; - if (!DisableIVRewrite) + if (EnableIVRewrite) IU = &getAnalysis(); LI = &getAnalysis(); SE = &getAnalysis(); @@ -1866,7 +1845,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // attempt to avoid evaluating SCEVs for sign/zero extend operations until // other expressions involving loop IVs have been evaluated. This helps SCEV // set no-wrap flags before normalizing sign/zero extension. - if (DisableIVRewrite) { + if (!EnableIVRewrite) { Rewriter.disableCanonicalMode(); SimplifyAndExtend(L, Rewriter, LPM); } @@ -1881,26 +1860,25 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { RewriteLoopExitValues(L, Rewriter); // Eliminate redundant IV users. - if (!DisableIVRewrite) + if (EnableIVRewrite) Changed |= simplifyIVUsers(IU, SE, &LPM, DeadInsts); // Eliminate redundant IV cycles. - if (DisableIVRewrite) + if (!EnableIVRewrite) SimplifyCongruentIVs(L); // Compute the type of the largest recurrence expression, and decide whether // a canonical induction variable should be inserted. Type *LargestType = 0; bool NeedCannIV = false; - bool ReuseIVForExit = DisableIVRewrite && !ForceLFTR; bool ExpandBECount = canExpandBackedgeTakenCount(L, SE); - if (ExpandBECount && !ReuseIVForExit) { + if (EnableIVRewrite && ExpandBECount) { // If we have a known trip count and a single exit block, we'll be // rewriting the loop exit test condition below, which requires a // canonical induction variable. NeedCannIV = true; Type *Ty = BackedgeTakenCount->getType(); - if (DisableIVRewrite) { + if (!EnableIVRewrite) { // In this mode, SimplifyIVUsers may have already widened the IV used by // the backedge test and inserted a Trunc on the compare's operand. Get // the wider type to avoid creating a redundant narrow IV only used by the @@ -1912,7 +1890,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { SE->getTypeSizeInBits(LargestType)) LargestType = SE->getEffectiveSCEVType(Ty); } - if (!DisableIVRewrite) { + if (EnableIVRewrite) { for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) { NeedCannIV = true; Type *Ty = @@ -1957,7 +1935,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { OldCannIV->insertBefore(L->getHeader()->getFirstInsertionPt()); } } - else if (ExpandBECount && ReuseIVForExit && needsLFTR(L, DT)) { + else if (!EnableIVRewrite && ExpandBECount && needsLFTR(L, DT)) { IndVar = FindLoopCounter(L, BackedgeTakenCount, SE, DT, TD); } // If we have a trip count expression, rewrite the loop's exit condition @@ -1978,7 +1956,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar, Rewriter); } // Rewrite IV-derived expressions. - if (!DisableIVRewrite) + if (EnableIVRewrite) RewriteIVExpressions(L, Rewriter); // Clear the rewriter cache, because values that are in the rewriter's cache @@ -2015,7 +1993,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // Verify that LFTR, and any other change have not interfered with SCEV's // ability to compute trip count. #ifndef NDEBUG - if (DisableIVRewrite && VerifyIndvars && + if (!EnableIVRewrite && VerifyIndvars && !isa(BackedgeTakenCount)) { SE->forgetLoop(L); const SCEV *NewBECount = SE->getBackedgeTakenCount(L); diff --git a/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll b/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll index 4dc3c1ea48c..77354f75106 100644 --- a/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll +++ b/test/Transforms/IndVarSimplify/2011-09-10-widen-nsw.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; Test WidenIV::GetExtendedOperandRecurrence. ; add219 should be extended to i64 because it is nsw, even though its ; sext cannot be hoisted outside the loop. diff --git a/test/Transforms/IndVarSimplify/ada-loops.ll b/test/Transforms/IndVarSimplify/ada-loops.ll index da7ecb66c54..2a460583e66 100644 --- a/test/Transforms/IndVarSimplify/ada-loops.ll +++ b/test/Transforms/IndVarSimplify/ada-loops.ll @@ -1,5 +1,5 @@ ; RUN: opt < %s -indvars -S | FileCheck %s -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; ; PR1301 diff --git a/test/Transforms/IndVarSimplify/elim-extend.ll b/test/Transforms/IndVarSimplify/elim-extend.ll index 0367e117e67..43c162fed7f 100644 --- a/test/Transforms/IndVarSimplify/elim-extend.ll +++ b/test/Transforms/IndVarSimplify/elim-extend.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s 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" diff --git a/test/Transforms/IndVarSimplify/iv-fold.ll b/test/Transforms/IndVarSimplify/iv-fold.ll index 7e11cdf098b..27700798be8 100644 --- a/test/Transforms/IndVarSimplify/iv-fold.ll +++ b/test/Transforms/IndVarSimplify/iv-fold.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s 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" diff --git a/test/Transforms/IndVarSimplify/iv-zext.ll b/test/Transforms/IndVarSimplify/iv-zext.ll index 3a05c893fb4..d07572a98a2 100644 --- a/test/Transforms/IndVarSimplify/iv-zext.ll +++ b/test/Transforms/IndVarSimplify/iv-zext.ll @@ -1,5 +1,5 @@ ; RUN: opt < %s -indvars -S | FileCheck %s -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; CHECK-NOT: and ; CHECK-NOT: zext diff --git a/test/Transforms/IndVarSimplify/lftr-reuse.ll b/test/Transforms/IndVarSimplify/lftr-reuse.ll index 6ccd1a424c7..490eee9c221 100644 --- a/test/Transforms/IndVarSimplify/lftr-reuse.ll +++ b/test/Transforms/IndVarSimplify/lftr-reuse.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; ; Make sure that indvars can perform LFTR without a canonical IV. diff --git a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll index eb8cef66c69..79485837d5f 100644 --- a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll +++ b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; ; Make sure that indvars isn't inserting canonical IVs. ; This is kinda hard to do until linear function test replacement is removed. diff --git a/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll b/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll index 5063b174544..22e209283b7 100644 --- a/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll +++ b/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll @@ -1,5 +1,5 @@ ; RUN: opt < %s -indvars -S | FileCheck %s -; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s ; Indvars should insert a 64-bit induction variable to eliminate the ; sext for the addressing, however it shouldn't eliminate the sext diff --git a/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll b/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll index ace74ffb862..fc906cdcfb1 100644 --- a/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll +++ b/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll @@ -1,5 +1,5 @@ ; RUN: opt < %s -indvars -instcombine -S | FileCheck %s -; RUN: opt < %s -indvars -disable-iv-rewrite -instcombine -S | FileCheck %s +; RUN: opt < %s -indvars -enable-iv-rewrite=false -instcombine -S | FileCheck %s ; ; Test that -indvars can reduce variable stride IVs. If it can reduce variable ; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without diff --git a/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll b/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll index 4a5cbf96727..59551d5c720 100644 --- a/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll +++ b/test/Transforms/LoopUnroll/2011-08-09-IVSimplify.ll @@ -1,4 +1,4 @@ -; RUN: opt -S < %s -loop-unroll -unroll-count=4 -disable-iv-rewrite | FileCheck %s +; RUN: opt -S < %s -loop-unroll -unroll-count=4 -enable-iv-rewrite=false | FileCheck %s ; ; Test induction variable simplify after loop unrolling. It should ; expose nice opportunities for GVN. -- 2.34.1