hanchenye-llvm-project/llvm/test/Transforms
Philip Reames eda1ba65ca LFTR for multiple exit loops
Teach IndVarSimply's LinearFunctionTestReplace transform to handle multiple exit loops. LFTR does two key things 1) it rewrites (all) exit tests in terms of a common IV potentially eliminating one in the process and 2) it moves any offset/indexing/f(i) style logic out of the loop.

This turns out to actually be pretty easy to implement. SCEV already has all the information we need to know what the backedge taken count is for each individual exit. (We use that when computing the BE taken count for the loop as a whole.) We basically just need to iterate through the exiting blocks and apply the existing logic with the exit specific BE taken count. (The previously landed NFC makes this super obvious.)

I chose to go ahead and apply this to all loop exits instead of only latch exits as originally proposed. After reviewing other passes, the only case I could find where LFTR form was harmful was LoopPredication. I've fixed the latch case, and guards aren't LFTRed anyways. We'll have some more work to do on the way towards widenable_conditions, but that's easily deferred.

I do want to note that I added one bit after the review.  When running tests, I saw a new failure (no idea why didn't see previously) which pointed out LFTR can rewrite a constant condition back to a loop varying one.  This was theoretically possible with a single exit, but the zero case covered it in practice.  With multiple exits, we saw this happening in practice for the eliminate-comparison.ll test case because we'd compute a ExitCount for one of the exits which was guaranteed to never actually be reached.  Since LFTR ran after simplifyAndExtend, we'd immediately turn around and undo the simplication work we'd just done.  The solution seemed obvious, so I didn't bother with another round of review.

Differential Revision: https://reviews.llvm.org/D62625

llvm-svn: 363883
2019-06-19 21:58:25 +00:00
..
ADCE Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
AddDiscriminators Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
AggressiveInstCombine Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
AlignmentFromAssumptions Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
ArgumentPromotion [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
AtomicExpand [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
BDCE Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
BlockExtractor [BlockExtractor] Change the basic block separator from ',' to ';' 2019-04-29 16:14:00 +00:00
BranchFolding Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
CallSiteSplitting CallSiteSplitting: Respect convergent and noduplicate 2019-05-29 16:59:48 +00:00
CalledValuePropagation Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
CanonicalizeAliases Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
CodeExtractor [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
CodeGenPrepare [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
ConstProp Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
ConstantHoisting [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
ConstantMerge Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Coroutines [coroutines] Fix spills of static array allocas 2019-05-13 23:58:24 +00:00
CorrelatedValuePropagation Resubmit "[CorrelatedValuePropagation] Fix prof branch_weights metadata handling for SwitchInst" 2019-06-05 05:46:40 +00:00
CrossDSOCFI Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
DCE Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
DeadArgElim Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
DeadStoreElimination [DSE] Bugfix to avoid PartialStoreMerging involving non byte-sized stores 2019-05-24 08:32:02 +00:00
DivRemPairs [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
EarlyCSE [EarlyCSE] Fix hashing of self-compares 2019-06-17 19:11:28 +00:00
EliminateAvailableExternally Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
EntryExitInstrumenter Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
ExpandMemCmp/X86 [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
Float2Int Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
ForcedFunctionAttrs Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
FunctionAttrs Do not derive no-recurse attribute if function does not have exact definition. 2019-06-10 04:16:04 +00:00
FunctionImport Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GCOVProfiling Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GVN GVN: Handle addrspacecast 2019-05-18 14:36:06 +00:00
GVNHoist Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GVNSink Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GlobalDCE [IR] Disallow llvm.global_ctors and llvm.global_dtors of the 2-field form in textual format 2019-05-15 02:35:32 +00:00
GlobalMerge Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GlobalOpt [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
GlobalSplit Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
GuardWidening [GuardWidening] Wire up a NPM version of the LoopGuardWidening pass 2019-04-18 19:17:14 +00:00
HardwareLoops [CodeGen] Check for HardwareLoop Latch ExitBlock 2019-06-17 13:39:28 +00:00
HotColdSplit [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
IPConstantProp Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
IRCE [SCEV] Pass NoWrapFlags when expanding an AddExpr 2019-06-14 09:19:41 +00:00
IndVarSimplify LFTR for multiple exit loops 2019-06-19 21:58:25 +00:00
IndirectBrExpand Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
InferAddressSpaces InferAddressSpaces: Fix cloning original addrspacecast 2019-06-17 14:13:29 +00:00
InferFunctionAttrs Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Inline [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
InstCombine [InstCombine] Fold icmp eq/ne (and %x, signbit), 0 -> %x s>=/s< 0 earlier 2019-06-19 17:31:39 +00:00
InstMerge Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
InstNamer Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
InstSimplify [InstSimplify] add a phi test with 1 incoming value; NFC 2019-06-19 17:23:29 +00:00
InterleavedAccess Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Internalize Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
JumpThreading [JumpThreading] A bug fix for stale loop info after unfold select 2019-05-15 15:15:16 +00:00
LCSSA Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LICM [LICM] Allow AliasSetMap to contain top-level loops. 2019-05-14 19:41:36 +00:00
LoadStoreVectorizer [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
LoopDataPrefetch Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopDeletion Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopDistribute LoopDistribute/LAA: Respect convergent 2019-06-12 13:34:19 +00:00
LoopFusion Add basic loop fusion pass. 2019-04-17 18:53:27 +00:00
LoopIdiom [DebugInfo@O2][LoopVectorize] pr39024: Vectorized code linenos step through loop even after completion 2019-06-19 10:50:47 +00:00
LoopInstSimplify Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopInterchange [LoopInterchange] Fix handling of LCSSA nodes defined in headers and latches. 2019-05-26 23:38:25 +00:00
LoopLoadElim LoopLoadElim: Respect convergent 2019-06-12 13:50:47 +00:00
LoopPredication [LoopPred] Fix a bug in unconditional latch bailout introduced in r362284 2019-06-06 18:02:36 +00:00
LoopReroll [SCEV] Use NoWrapFlags when expanding a simple mul 2019-06-17 10:05:18 +00:00
LoopRotate Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopSimplify [DebugInfo@O2][LoopVectorize] pr39024: Vectorized code linenos step through loop even after completion 2019-06-19 10:50:47 +00:00
LoopSimplifyCFG Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopStrengthReduce [NFC][LSR] Avoid undefined grep in pr2570.ll 2019-06-19 16:02:54 +00:00
LoopTransformWarning Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopUnroll [DebugInfo@O2][LoopVectorize] pr39024: Vectorized code linenos step through loop even after completion 2019-06-19 10:50:47 +00:00
LoopUnrollAndJam Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopUnswitch Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LoopVectorize [DebugInfo@O2][LoopVectorize] pr39024: Vectorized code linenos step through loop even after completion 2019-06-19 10:50:47 +00:00
LoopVersioning LoopVersioning: Respect convergent 2019-06-12 14:05:58 +00:00
LoopVersioningLICM LoopVersioningLICM: Respect convergent and noduplicate 2019-05-29 20:47:59 +00:00
LowerAtomic Transforms: lower fadd and fsub atomicrmw instructions 2019-05-23 17:03:43 +00:00
LowerExpectIntrinsic Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LowerGuardIntrinsic Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LowerInvoke Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
LowerSwitch Fix a crash when the default of a switch is removed 2019-06-03 17:54:15 +00:00
LowerTypeTests [ThinLTO] Auto-hide prevailing linkonce_odr only when all copies eligible 2019-05-10 20:08:24 +00:00
LowerWidenableCondition Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
MakeGuardsExplicit Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Mem2Reg Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
MemCpyOpt Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
MergeFunc Fix 2-field llvm.global_ctors `REQUIRES: asserts` tests after rL360742 2019-05-15 03:08:21 +00:00
MergeICmps [MergeICmps] Make the pass compatible with the new pass manager. 2019-05-23 12:35:26 +00:00
MetaRenamer Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
NameAnonGlobals Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
NaryReassociate Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
NewGVN NewGVN: Handle addrspacecast 2019-06-05 21:15:52 +00:00
ObjCARC [ObjC][ARC] Delete ObjC runtime calls on global variables annotated 2019-06-14 22:06:32 +00:00
PGOProfile [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
PartiallyInlineLibCalls Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
PhaseOrdering [Pass Pipeline][NFC] Add a test prior to committing D61726 2019-05-13 21:14:36 +00:00
PlaceSafepoints Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
PreISelIntrinsicLowering Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
PruneEH Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Reassociate [Reassociate] Handle unary FNeg in the Reassociate pass 2019-06-19 14:59:14 +00:00
Reg2Mem Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
RewriteStatepointsForGC Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
SCCP [SCCP] Add UnaryOperator visitor to SCCP for unary FNeg 2019-06-03 21:53:56 +00:00
SLPVectorizer [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
SROA Recommit [SROA] Enhance SROA to handle `addrspacecast`ed allocas 2019-06-18 21:41:13 +00:00
SafeStack [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
SampleProfile Fix prof branch_weights in entry_counts_missing_dbginfo.ll test 2019-05-16 03:39:09 +00:00
ScalarizeMaskedMemIntrin/X86 Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
Scalarizer [Scalarizer] Add UnaryOperator visitor to scalarization pass 2019-06-04 23:01:36 +00:00
SeparateConstOffsetFromGEP [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
SimpleLoopUnswitch [NewPM] Add Option handling for SimpleLoopUnswitch 2019-04-22 10:35:07 +00:00
SimplifyCFG [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
Sink Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
SpeculateAroundPHIs SpeculateAroundPHIs: Respect convergent 2019-05-29 13:14:39 +00:00
SpeculativeExecution Support FNeg in SpeculativeExecution pass 2019-05-14 16:51:18 +00:00
StackProtector/X86 [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
StraightLineStrengthReduce Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
StripDeadPrototypes Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
StripSymbols Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
StructurizeCFG StructurizeCFG: Relax uniformity checks. 2019-05-24 08:59:17 +00:00
SyntheticCountsPropagation Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
TailCallElim Revert "Temporarily Revert "Add basic loop fusion pass."" 2019-04-17 04:52:47 +00:00
ThinLTOBitcodeWriter [lit] Delete empty lines at the end of lit.local.cfg NFC 2019-06-17 09:51:07 +00:00
Util [PredicateInfo] Do not process unreachable operands. 2019-05-15 19:35:38 +00:00
WholeProgramDevirt [ThinLTO] Auto-hide prevailing linkonce_odr only when all copies eligible 2019-05-10 20:08:24 +00:00