llvm-project/llvm/lib/Analysis
Arthur Eubanks ddc702376a [NewPM] Don't skip SCCs not in current RefSCC
With D107249 I saw huge compile time regressions on a module (150s ->
5700s). This turned out to be due to a huge RefSCC in
the module. As we ran the function simplification pipeline on functions
in the SCCs in the RefSCC, some of those SCCs would be split out to
their RefSCC, a child of the current RefSCC. We'd skip the remaining
SCCs in the huge RefSCC because the current RefSCC is now the RefSCC
just split out, then revisit the original huge RefSCC from the
beginning.  This happened many times because many functions in the
RefSCC were optimizable to the point of becoming their own RefSCC.

This patch makes it so we don't skip SCCs not in the current RefSCC so
that we split out all the child RefSCCs on the first iteration of
RefSCC. When we split out a RefSCC, we invalidate the original RefSCC
and add the remainder of the SCCs into a new RefSCC in
RCWorklist. This happens repeatedly until we finish visiting all
SCCs, at which point there is only one valid RefSCC in
RCWorklist from the original RefSCC containing all the SCCs that
were not split out, and we visit that.

For example, in the newly added test cgscc-refscc-mutation-order.ll,
we'd previously run instcombine in this order:
f1, f2, f1, f3, f1, f4, f1

Now it's:
f1, f2, f3, f4, f1

This can cause more passes to be run in some specific cases,
e.g. if f1<->f2 gets optimized to f1<-f2, we'd previously run f1, f2;
now we run f1, f2, f2.

This improves kimwitu++ compile times by a lot (12-15% for various -O3 configs):
https://llvm-compile-time-tracker.com/compare.php?from=2371c5a0e06d22b48da0427cebaf53a5e5c54635&to=00908f1d67400cab1ad7bcd7cacc7558d1672e97&stat=instructions

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D121953
2022-03-18 14:16:29 -07:00
..
models [MLGO] ML Regalloc Eviction Advisor 2022-01-19 11:00:32 -08:00
AliasAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
AliasAnalysisEvaluator.cpp [AAEval] Remove unused function (NFC) 2022-03-16 10:25:45 +01:00
AliasAnalysisSummary.cpp
AliasAnalysisSummary.h
AliasSetTracker.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
Analysis.cpp Reapply CycleInfo: Introduce cycles as a generalization of loops 2021-12-10 14:36:43 +05:30
AssumeBundleQueries.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
AssumptionCache.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
BasicAliasAnalysis.cpp [BasicAA] Account for wrapping when using abs(VarIndex) >= abs(Scale). 2022-03-18 14:41:15 +00:00
BlockFrequencyInfo.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
BlockFrequencyInfoImpl.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
BranchProbabilityInfo.cpp [NFC] Add missing <map> includes 2022-01-19 12:29:03 +01:00
CFG.cpp [CFG] Move reachable from entry checks into basic block variant 2021-05-15 15:42:02 +02:00
CFGPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
CFLAndersAliasAnalysis.cpp
CFLGraph.h
CFLSteensAliasAnalysis.cpp [llvm] Remove redundant member initialization (NFC) 2022-01-07 17:45:09 -08:00
CGSCCPassManager.cpp [NewPM] Don't skip SCCs not in current RefSCC 2022-03-18 14:16:29 -07:00
CMakeLists.txt [NFC][mlgo]Make the test model generator inlining-specific 2021-12-22 13:38:45 -08:00
CallGraph.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
CallGraphSCCPass.cpp [LegacyPassManager] Move structural hashing into Pass classes. NFC. 2022-03-17 09:51:12 +00:00
CallPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
CaptureTracking.cpp [CaptureTracking][NFCI] Expose capture tracking logic 2022-03-11 22:56:16 -06:00
CmpInstAnalysis.cpp [InstCombine][Analysis] Move getFCmpCode and getPredForFCmpCode to CmpInstAnalysis. NFC 2022-03-03 09:33:24 -08:00
CodeMetrics.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ConstantFolding.cpp [ConstFold] Don't fold calls with mismatching function type 2022-03-11 14:09:23 +01:00
ConstraintSystem.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
CostModel.cpp [CostModel] Change printer pass wording to work with update_analyze_test_checks.py 2022-03-03 10:10:48 -08:00
CycleAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
DDG.cpp [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
DDGPrinter.cpp
Delinearization.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
DemandedBits.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
DependenceAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
DependenceGraphBuilder.cpp [NFC] Remove unnecessary #includes 2022-02-04 21:22:41 -08:00
DevelopmentModeInlineAdvisor.cpp Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
DivergenceAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
DomPrinter.cpp Introduce NewPM .dot printers for DomTree 2022-01-05 23:25:40 +00:00
DomTreeUpdater.cpp [NFC] Remove unnecessary "#include"s from header files 2022-02-23 01:20:48 -08:00
DominanceFrontier.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
EHPersonalities.cpp
FunctionPropertiesAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
GlobalsModRef.cpp [NewPM] Actually recompute GlobalsAA before module optimization pipeline 2022-03-14 09:42:34 -07:00
GuardUtils.cpp
HeatUtils.cpp [llvm][clang][NFC] updates inline licence info 2021-08-11 02:48:53 +00:00
IRSimilarityIdentifier.cpp [IRSim] Make sure the first instruction of a block doesn't get missed if it is the first valid instruction in Module. 2022-03-13 23:13:09 -05:00
IVDescriptors.cpp [IVDescriptors] Bail out instead of asserting that order is expected. 2022-03-07 19:57:26 +00:00
IVUsers.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ImportedFunctionsInliningStatistics.cpp
IndirectCallPromotionAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
InlineAdvisor.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
InlineCost.cpp [InlineCost] Add cl::opt for target attributes compatibility check. NFC 2022-03-11 18:05:16 -05:00
InlineSizeEstimatorAnalysis.cpp Fix build breaks on ml-* bots introduced by include cleanups 2022-03-01 11:29:18 -08:00
InstCount.cpp
InstructionPrecedenceTracking.cpp Revert "[IPT] Restructure cache to allow lazy update following invalidation [NFC]" 2021-10-21 10:48:41 -07:00
InstructionSimplify.cpp [InstSimplify] Handle vector GEP when simplifying zero indices 2022-03-11 10:56:44 +01:00
Interval.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
IntervalPartition.cpp [llvm] Use range-based for loops (NFC) 2021-11-20 18:42:10 -08:00
LazyBlockFrequencyInfo.cpp
LazyBranchProbabilityInfo.cpp
LazyCallGraph.cpp Add missing include under EXPENSIVE_CHECKS 2022-03-12 18:54:29 +01:00
LazyValueInfo.cpp [NFC] Add LazyValueInfo::clear method 2022-03-15 17:52:50 +07:00
LegacyDivergenceAnalysis.cpp [NFC] Remove unnecessary #includes 2022-02-04 21:22:41 -08:00
Lint.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
Loads.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
LoopAccessAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
LoopAnalysisManager.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
LoopCacheAnalysis.cpp [llvm] Remove redundant member initialization (NFC) 2022-01-07 17:45:09 -08:00
LoopInfo.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
LoopNestAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
LoopPass.cpp [LegacyPassManager] Move structural hashing into Pass classes. NFC. 2022-03-17 09:51:12 +00:00
LoopUnrollAnalyzer.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
MLInlineAdvisor.cpp Fix build breaks on ml-* bots introduced by include cleanups 2022-03-01 11:29:18 -08:00
MemDepPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
MemDerefPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
MemoryBuiltins.cpp getAllocAlignment: respect allocalign attribute if present 2022-03-04 15:57:54 -05:00
MemoryDependenceAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
MemoryLocation.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
MemorySSA.cpp [MemorySSA] Don't optimize uses during construction 2022-03-18 09:56:16 +01:00
MemorySSAUpdater.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ModelUnderTrainingRunner.cpp [NFC][MLGO] Remove the word "inliner" in a generic error message. 2022-01-11 12:39:16 -08:00
ModuleDebugInfoPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ModuleSummaryAnalysis.cpp [LTO] Initialize canAutoHide() using canBeOmittedFromSymbolTable() 2022-03-03 19:04:11 -05:00
MustExecute.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
NoInferenceModelRunner.cpp [NFC][MLGO]Add RTTI support for MLModelRunner and simplify runner setup 2022-01-04 19:46:14 -08:00
ObjCARCAliasAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ObjCARCAnalysisUtils.cpp
ObjCARCInstKind.cpp [ObjCARC] Use "UnsafeClaimRV" to refer to unsafeClaim in enums. NFC. 2022-01-24 19:37:01 -08:00
OptimizationRemarkEmitter.cpp
OverflowInstAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
PHITransAddr.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
PhiValues.cpp
PostDominators.cpp
ProfileSummaryInfo.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
PtrUseVisitor.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
README.txt
RegionInfo.cpp [NFC] Remove unnecessary #includes 2022-02-04 21:22:41 -08:00
RegionPass.cpp [LegacyPassManager] Move structural hashing into Pass classes. NFC. 2022-03-17 09:51:12 +00:00
RegionPrinter.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ReplayInlineAdvisor.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ScalarEvolution.cpp [SCEV] Use constant ranges when determining reachable blocks (PR54434) 2022-03-18 12:04:35 +01:00
ScalarEvolutionAliasAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ScalarEvolutionDivision.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ScalarEvolutionNormalization.cpp Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
ScopedNoAliasAA.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
StackLifetime.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
StackSafetyAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
StratifiedSets.h
SyncDependenceAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
SyntheticCountsUtils.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
TFUtils.cpp [MLGO] Add support for multiple training traces per module 2022-01-11 16:13:31 -08:00
TargetLibraryInfo.cpp [TLI] Check that malloc argument has type size_t 2022-03-14 17:22:24 +01:00
TargetTransformInfo.cpp Revert "[SLP] Fix lookahead operand reordering for splat loads." due to build failures 2022-03-17 18:22:04 -07:00
Trace.cpp
TypeBasedAliasAnalysis.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
TypeMetadataUtils.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
VFABIDemangling.cpp Cleanup includes: LLVMAnalysis 2022-03-01 18:01:54 +01:00
ValueLattice.cpp
ValueLatticeUtils.cpp [SCCP] Check that load/store and global type match 2022-02-11 11:01:18 +01:00
ValueTracking.cpp [FPEnv][InstSimplify] Teach CannotBeNegativeZero() about constrained intrinsics. 2022-03-18 10:24:48 -04:00
VectorUtils.cpp [Analysis] add utility function for unary shuffle mask creation 2021-10-18 09:00:39 -04:00

README.txt

Analysis Opportunities:

//===---------------------------------------------------------------------===//

In test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll, the
ScalarEvolution expression for %r is this:

  {1,+,3,+,2}<loop>

Outside the loop, this could be evaluated simply as (%n * %n), however
ScalarEvolution currently evaluates it as

  (-2 + (2 * (trunc i65 (((zext i64 (-2 + %n) to i65) * (zext i64 (-1 + %n) to i65)) /u 2) to i64)) + (3 * %n))

In addition to being much more complicated, it involves i65 arithmetic,
which is very inefficient when expanded into code.

//===---------------------------------------------------------------------===//

In formatValue in test/CodeGen/X86/lsr-delayed-fold.ll,

ScalarEvolution is forming this expression:

((trunc i64 (-1 * %arg5) to i32) + (trunc i64 %arg5 to i32) + (-1 * (trunc i64 undef to i32)))

This could be folded to

(-1 * (trunc i64 undef to i32))

//===---------------------------------------------------------------------===//