llvm/lib/Analysis
Silviu Baranga 0c35941274 [SCEV] Generalize the SCEV algorithm for creating expressions for PHI nodes
Summary:
When forming expressions for phi nodes having an incoming value from
outside the loop A and a value coming from the previous iteration B
we were forming an AddRec if:
  - B was an AddRec
  - the value A was equal to the value for B at iteration -1 (or equal
    to the value of B shifted by one iteration, at iteration 0)

In this case, we were computing the expression to be the expression of
B, shifted by one iteration.

This changes generalizes the logic above by removing the restriction that
B needs to be an AddRec. For this we introduce two expression rewriters
that allow us to
  - shift an expression by one iteration
  - get the value of an expression at iteration 0

This allows us to get SCEV expressions for PHI nodes when these expressions
are not AddRecExprs.

Reviewers: sanjoy

Subscribers: llvm-commits, sanjoy

Differential Revision: http://reviews.llvm.org/D14175

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251700 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-30 15:02:28 +00:00
..
AliasAnalysis.cpp
AliasAnalysisEvaluator.cpp
AliasSetTracker.cpp Revert "r251451 - [AliasSetTracker] Use mod/ref information for UnknownInstr" 2015-10-28 22:13:41 +00:00
Analysis.cpp
AssumptionCache.cpp
BasicAliasAnalysis.cpp [AliasAnalysis] Take into account readnone attribute for the function arguments 2015-10-28 17:54:48 +00:00
BlockFrequencyInfo.cpp
BlockFrequencyInfoImpl.cpp
BranchProbabilityInfo.cpp Check the case that the numerator and denominator are both zeros when getting edge probabilities in BPI and return 100% in this case. 2015-10-26 18:00:17 +00:00
CallGraph.cpp
CallGraphSCCPass.cpp
CallPrinter.cpp
CaptureTracking.cpp
CFG.cpp
CFGPrinter.cpp
CFLAliasAnalysis.cpp
CGSCCPassManager.cpp
CMakeLists.txt
CodeMetrics.cpp Use all_of to simplify control flow. NFC. 2015-10-24 19:30:37 +00:00
ConstantFolding.cpp
CostModel.cpp
Delinearization.cpp
DemandedBits.cpp
DependenceAnalysis.cpp
DivergenceAnalysis.cpp
DominanceFrontier.cpp
DomPrinter.cpp
GlobalsModRef.cpp [GlobalsAA] An indirect global that is initialized is not fair game 2015-10-28 10:41:29 +00:00
InlineCost.cpp
InstCount.cpp
InstructionSimplify.cpp [InstSimplify] sgt on i1s also encodes implication 2015-10-29 03:19:10 +00:00
Interval.cpp
IntervalPartition.cpp
IteratedDominanceFrontier.cpp
IVUsers.cpp
LazyCallGraph.cpp
LazyValueInfo.cpp Fix an unused variable warning which broke the clang-cmake-mips builder 2015-10-29 04:21:49 +00:00
LibCallSemantics.cpp
Lint.cpp
LLVMBuild.txt
Loads.cpp
LoopAccessAnalysis.cpp Put global classes into the appropriate namespace. 2015-10-28 13:54:36 +00:00
LoopInfo.cpp
LoopPass.cpp
Makefile
MemDepPrinter.cpp
MemDerefPrinter.cpp
MemoryBuiltins.cpp Use find_if to simplify control flow. NFC. 2015-10-24 19:03:15 +00:00
MemoryDependenceAnalysis.cpp
MemoryLocation.cpp
ModuleDebugInfoPrinter.cpp
ObjCARCAliasAnalysis.cpp
ObjCARCAnalysisUtils.cpp
ObjCARCInstKind.cpp
OrderedBasicBlock.cpp
PHITransAddr.cpp
PostDominators.cpp
PtrUseVisitor.cpp
README.txt
RegionInfo.cpp
RegionPass.cpp
RegionPrinter.cpp
ScalarEvolution.cpp [SCEV] Generalize the SCEV algorithm for creating expressions for PHI nodes 2015-10-30 15:02:28 +00:00
ScalarEvolutionAliasAnalysis.cpp
ScalarEvolutionExpander.cpp [ScalarEvolutionExpander] PHI on a catchpad can be used on both edges 2015-10-27 19:48:28 +00:00
ScalarEvolutionNormalization.cpp
ScopedNoAliasAA.cpp
SparsePropagation.cpp
StratifiedSets.h
TargetLibraryInfo.cpp ARM: teach backend about WatchOS and TvOS libcalls. 2015-10-28 22:51:16 +00:00
TargetTransformInfo.cpp Scalarizer for masked.gather and masked.scatter intrinsics. 2015-10-25 15:37:55 +00:00
Trace.cpp
TypeBasedAliasAnalysis.cpp
ValueTracking.cpp [ValueTracking] Expose implies via ValueTracking, NFC 2015-10-28 03:20:19 +00:00
VectorUtils.cpp

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

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