From 225df71951cb7b870d078167de1a375a674c79df Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Fri, 9 Oct 2020 18:28:12 +0700 Subject: [PATCH] [NFC] Add option to disable IV widening if needed IV widening is sometimes a strictly harmful transform (some examples of this are shown in tests 11, 12 in widen-loop-comp.ll). One of the reasons of this is that sometimes SCEV fails to prove some facts after part of guards has been widened. Though each single such case looks like a bug that can be addressed, it seems that disabling of IV widening may be profitable in some cases. We want to have an option to do so. By default, existing behavior is preserved and IV widening is on. --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index dd85fafc3a13..602d1ec572cd 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -131,6 +131,10 @@ static cl::opt LoopPredication("indvars-predicate-loops", cl::Hidden, cl::init(true), cl::desc("Predicate conditions in read only loops")); +static cl::opt +AllowIVWidening("indvars-widen-indvars", cl::Hidden, cl::init(true), + cl::desc("Allow widening of indvars to eliminate s/zext")); + namespace { struct RewritePhi; @@ -1392,6 +1396,10 @@ void WidenIV::pushNarrowIVUsers(Instruction *NarrowDef, Instruction *WideDef) { /// It would be simpler to delete uses as they are processed, but we must avoid /// invalidating SCEV expressions. PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) { + // Bail if we disallowed widening. + if(!AllowIVWidening) + return nullptr; + // Is this phi an induction variable? const SCEVAddRecExpr *AddRec = dyn_cast(SE->getSCEV(OrigPhi)); if (!AddRec)