1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
llvm-mirror/lib/Analysis
Nikita Popov 8a70d8f6d7 [InstSimplify] Remove known bits constant folding
If SimplifyInstruction() does not succeed in simplifying the
instruction, it will compute the known bits of the instruction
in the hope that all bits are known and the instruction can be
folded to a constant. I have removed a similar optimization
from InstCombine in D75801, and would like to drop this one as well.

On average, we spend ~1% of total compile-time performing this
known bits calculation. However, if we introduce some additional
statistics for known bits computations and how many of them succeed
in simplifying the instruction we get (on test-suite):

    instsimplify.NumKnownBits: 216
    instsimplify.NumKnownBitsComputed: 13828375
    valuetracking.NumKnownBitsComputed: 45860806

Out of ~14M known bits calculations (accounting for approximately
one third of all known bits calculations), only 0.0015% succeed in
producing a constant. Those cases where we do succeed to compute
all known bits will get folded by other passes like InstCombine
later. On test-suite, only lencod.test and GCC-C-execute-pr44858.test
show a hash difference after this change. On lencod we see an
improvement (a loop phi is optimized away), on the GCC torture
test a regression (a function return value is determined only
after IPSCCP, preventing propagation from a noinline function.)

There are various regressions in InstSimplify tests. However, all
of these cases are already handled by InstCombine, and corresponding
tests have already been added there.

Differential Revision: https://reviews.llvm.org/D79294
2020-05-03 20:26:58 +02:00
..
AliasAnalysis.cpp [IR] Lazily number instructions for local dominance queries 2020-02-18 14:44:24 -08:00
AliasAnalysisEvaluator.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
AliasAnalysisSummary.cpp AliasAnalysisSummary.h - cleanup includes and forward declarations. NFC. 2020-04-21 11:32:58 +01:00
AliasAnalysisSummary.h AliasAnalysisSummary.h - cleanup includes and forward declarations. NFC. 2020-04-21 11:32:58 +01:00
AliasSetTracker.cpp [NFC] Remove trailing space 2020-02-18 10:49:13 +08:00
Analysis.cpp
AssumeBundleQueries.cpp [AssumeBundles] Refactor asssume builder 2020-04-25 13:43:52 +02:00
AssumptionCache.cpp [AssumeBundles] adapt Assumption cache to assume bundles 2020-04-13 12:04:51 +02:00
BasicAliasAnalysis.cpp [SVE] Remove calls to VectorType::isScalable from analysis 2020-04-23 12:44:22 -07:00
BlockFrequencyInfo.cpp [CFG/BasicBlock] Rename succ_const to const_succ. [NFC] 2020-03-25 12:40:55 -07:00
BlockFrequencyInfoImpl.cpp [BFI] Add a debug check for unknown block queries. 2020-02-04 10:05:28 -08:00
BranchProbabilityInfo.cpp [BPI] Incorrect probability reported in case of mulptiple edges. 2020-04-30 11:41:03 +07:00
CallGraph.cpp [CallGraphUpdater] Update the ExternalCallingNode for node replacements 2020-04-15 18:38:50 -05:00
CallGraphSCCPass.cpp [CallGraphUpdater][NFC] Minor updates to D77855 2020-04-15 21:26:35 -05:00
CallPrinter.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
CaptureTracking.cpp [CaptureTracking] Make MaxUsesToExplore cheaper (NFC) 2020-04-26 09:54:15 +02:00
CFG.cpp [CFG/BasicBlock] Rename succ_const to const_succ. [NFC] 2020-03-25 12:40:55 -07:00
CFGPrinter.cpp [CFG] Turning on Heat Colors for CFG by default 2020-04-29 20:44:10 +00:00
CFLAndersAliasAnalysis.cpp [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers. 2020-04-14 14:11:02 +03:00
CFLGraph.h
CFLSteensAliasAnalysis.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
CGSCCPassManager.cpp [llvm][NFC][CallSite] Remove Implementation uses of CallSite 2020-04-14 14:49:47 -07:00
CMakeLists.txt Revert "Move ModuleSummaryAnalysis from libAnalysis to libObject to break the dependency from Analysis to Object" 2020-04-14 00:27:08 +00:00
CmpInstAnalysis.cpp
CodeMetrics.cpp [TTI] Add TargetCostKind argument to getUserCost 2020-04-28 08:57:45 +01:00
ConstantFolding.cpp [SVE] Remove calls to VectorType::isScalable from analysis 2020-04-23 12:44:22 -07:00
CostModel.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
DDG.cpp [DDG] Data Dependence Graph - Graph Simplification 2020-02-19 13:41:51 -05:00
Delinearization.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
DemandedBits.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
DependenceAnalysis.cpp [DA] Delinearization of fixed-size multi-dimensional arrays 2020-02-27 10:29:01 -05:00
DependenceGraphBuilder.cpp [DDG] Data Dependence Graph - Graph Simplification 2020-02-19 13:41:51 -05:00
DivergenceAnalysis.cpp [DA] Don't propagate from unreachable blocks 2020-01-24 10:28:11 -08:00
DominanceFrontier.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
DomPrinter.cpp [CFGPrinter][CallPrinter][polly] Adding distinct structure for CFGDOTInfo 2020-04-06 17:42:54 +00:00
DomTreeUpdater.cpp [NFC] Fixes -Wrange-loop-analysis warnings 2020-01-01 20:01:37 +01:00
EHPersonalities.cpp
GlobalsModRef.cpp [GlobalsModRef] Add invalidate method 2020-01-17 10:33:54 -08:00
GuardUtils.cpp [NFC] Remove trailing space 2020-02-18 10:49:13 +08:00
HeatUtils.cpp HeatUtils.h - remove unnecessary includes. NFC. 2020-04-18 13:37:06 +01:00
IndirectCallPromotionAnalysis.cpp [CallSite removal] Remove unneeded includes of CallSite.h. NFC 2020-04-22 00:07:13 -07:00
InlineCost.cpp [InlineCost] Addressing a very strict assert check in CostAnnotationWriter::emitInstructionAnnot 2020-04-30 15:38:36 +00:00
InstCount.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
InstructionPrecedenceTracking.cpp [IPT] Don't use OrderedInstructions (NFC) 2020-04-20 18:25:31 +02:00
InstructionSimplify.cpp [InstSimplify] Remove known bits constant folding 2020-05-03 20:26:58 +02:00
Interval.cpp
IntervalPartition.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
IVDescriptors.cpp [IVDescriptors] Remove unnecessary DemandedBits.h include; NFC 2020-04-04 12:07:57 +02:00
IVUsers.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
LazyBlockFrequencyInfo.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
LazyBranchProbabilityInfo.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
LazyCallGraph.cpp [llvm][NFC][CallSite] Remove Implementation uses of CallSite 2020-04-14 14:49:47 -07:00
LazyValueInfo.cpp [ValueLattice] Merging unknown with empty CR is unknown. 2020-04-25 13:43:34 +01:00
LegacyDivergenceAnalysis.cpp Resubmit: [DA][TTI][AMDGPU] Add option to select GPUDA with TTI 2020-01-24 10:39:40 -08:00
Lint.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
LLVMBuild.txt Revert "Move ModuleSummaryAnalysis from libAnalysis to libObject to break the dependency from Analysis to Object" 2020-04-14 00:27:08 +00:00
Loads.cpp [SVE] Remove calls to VectorType::isScalable from analysis 2020-04-23 12:44:22 -07:00
LoopAccessAnalysis.cpp [LAA] Move CheckingPtrGroup/PointerCheck outside class (NFC). 2020-04-28 21:47:31 +01:00
LoopAnalysisManager.cpp Add PassManagerImpl.h to hide implementation details 2020-02-03 11:15:55 -08:00
LoopCacheAnalysis.cpp [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers. 2020-04-14 14:11:02 +03:00
LoopInfo.cpp [NFC] Add missing 'const' notion to LCSSA-related functions 2020-04-17 17:49:34 +07:00
LoopNestAnalysis.cpp [LoopNest]: Analysis to discover properties of a loop nest. 2020-03-03 18:25:19 +00:00
LoopPass.cpp NFC. Remove obsolete SimpleAnalysis infrastructure 2020-01-23 13:58:30 +07:00
LoopUnrollAnalyzer.cpp
MemDepPrinter.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
MemDerefPrinter.cpp [CallSite removal] Remove unneeded includes of CallSite.h. NFC 2020-04-22 00:07:13 -07:00
MemoryBuiltins.cpp [NFC] Rename *ByValOrInalloca* to *PassPointeeByValue* 2020-04-30 09:42:13 -07:00
MemoryDependenceAnalysis.cpp [DependenceAnalysis] Dependecies for loads marked with "ivnariant.load" should not be shared with general accesses(PR42151). 2020-03-04 18:40:02 +07:00
MemoryLocation.cpp [IR] Split out target specific intrinsic enums into separate headers 2019-12-11 18:02:14 -08:00
MemorySSA.cpp [MemorySSA] Pass DT to the upward iterator for proper PhiTranslation. 2020-04-29 14:28:31 -07:00
MemorySSAUpdater.cpp [GraphDiff] Extend GraphDiff to track a list of updates. 2020-04-03 12:10:36 -07:00
ModuleDebugInfoPrinter.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
ModuleSummaryAnalysis.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
MustExecute.cpp MustBeExecutedContextPrinter::runOnModule: Use unique_ptr to simplify/clarify ownership 2020-04-28 11:30:53 -07:00
ObjCARCAliasAnalysis.cpp [Pass] Ensure we don't include PassSupport.h or PassAnalysisSupport.h directly 2020-04-26 12:58:20 +01:00
ObjCARCAnalysisUtils.cpp
ObjCARCInstKind.cpp [llvm][NFC][CallSite] Remove remaining {Immutable}CallSite uses 2020-04-23 22:19:39 -07:00
OptimizationRemarkEmitter.cpp [BPI][NFC] Reuse post dominantor tree from analysis manager when available 2020-04-30 11:31:03 +07:00
OrderedInstructions.cpp [IR] Lazily number instructions for local dominance queries 2020-02-18 14:44:24 -08:00
PHITransAddr.cpp
PhiValues.cpp [PhiValues] Remove redundant map searches 2019-11-23 10:32:56 +02:00
PostDominators.cpp [CodeMoverUtils] Added an API to check if an instruction can be safely 2019-11-22 21:29:08 +00:00
ProfileSummaryInfo.cpp [llvm][NFC] Use CallBase instead of Instruction in ProfileSummaryInfo 2020-04-27 20:47:52 -07:00
PtrUseVisitor.cpp
README.txt
RegionInfo.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
RegionPass.cpp
RegionPrinter.cpp [CFGPrinter][CallPrinter][polly] Adding distinct structure for CFGDOTInfo 2020-04-06 17:42:54 +00:00
ScalarEvolution.cpp [SVE] Remove calls to VectorType::isScalable from analysis 2020-04-23 12:44:22 -07:00
ScalarEvolutionAliasAnalysis.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
ScalarEvolutionExpander.cpp Revert "[LSR] re-add testcase for wrongly phi node elimination - NFC" 2020-04-01 12:58:06 +00:00
ScalarEvolutionNormalization.cpp
ScopedNoAliasAA.cpp Sink all InitializePasses.h includes 2019-11-13 16:34:37 -08:00
StackSafetyAnalysis.cpp [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand(). 2020-04-27 22:17:03 -07:00
StratifiedSets.h
SyncDependenceAnalysis.cpp [CFG/BasicBlock] Rename succ_const to const_succ. [NFC] 2020-03-25 12:40:55 -07:00
SyntheticCountsUtils.cpp [CallSite removal] Remove unneeded includes of CallSite.h. NFC 2020-04-22 00:07:13 -07:00
TargetLibraryInfo.cpp [ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers. 2020-04-14 14:11:02 +03:00
TargetTransformInfo.cpp [TTI] Add DemandedElts to getScalarizationOverhead 2020-04-29 12:00:38 +01:00
Trace.cpp
TypeBasedAliasAnalysis.cpp [Metadata] Add TBAA struct metadata to AAMDNode 2020-01-06 11:05:15 +03:00
TypeMetadataUtils.cpp [llvm][NFC][CallSite] Remove CallSite from TypeMetadataUtils & related 2020-04-23 08:23:16 -07:00
ValueLattice.cpp [ValueLattice] Distinguish between constant ranges with/without undef. 2020-03-31 12:50:20 +01:00
ValueLatticeUtils.cpp
ValueTracking.cpp [ValueTracking] Short-circuit GEP known bits calculation (NFC) 2020-05-02 12:29:26 +02:00
VectorUtils.cpp [SVE] Remove calls to VectorType::isScalable from analysis 2020-04-23 12:44:22 -07:00
VFABIDemangling.cpp [llvm][VectorUtils] Tweak VFShape for scalable vector functions. 2020-01-30 05:53:56 +00:00

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))

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