diff options
author | Philip Reames <listmail@philipreames.com> | 2017-10-31 17:06:32 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2017-10-31 17:06:32 +0000 |
commit | cd0a5bb96c10e5febef08c6e4618a99fdd3fbb99 (patch) | |
tree | 6ace7af9d3a552439d5a97a66159c8e13aed5237 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 39970069b1087395b89e9d3bb66434c81bd49dd8 (diff) | |
download | llvm-cd0a5bb96c10e5febef08c6e4618a99fdd3fbb99.zip llvm-cd0a5bb96c10e5febef08c6e4618a99fdd3fbb99.tar.gz llvm-cd0a5bb96c10e5febef08c6e4618a99fdd3fbb99.tar.bz2 |
[IndVarSimplify] Simplify code using a dictionary
Possibly very slightly slower, but this code is not performance critical and the readability benefit alone is huge.
llvm-svn: 317012
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index bceb02a..fce7f8b 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -193,27 +193,19 @@ bool SimplifyIndvar::makeIVComparisonInvariant(ICmpInst *ICmp, // cheaply, where cheaply means "we don't need to emit any new // instructions". - Value *NewLHS = nullptr, *NewRHS = nullptr; - - if (S == InvariantLHS || X == InvariantLHS) - NewLHS = - ICmp->getOperand(S == InvariantLHS ? IVOperIdx : (1 - IVOperIdx)); - - if (S == InvariantRHS || X == InvariantRHS) - NewRHS = - ICmp->getOperand(S == InvariantRHS ? IVOperIdx : (1 - IVOperIdx)); - + SmallDenseMap<const SCEV*, Value*> CheapExpansions; + CheapExpansions[S] = ICmp->getOperand(IVOperIdx); + CheapExpansions[X] = ICmp->getOperand(1 - IVOperIdx); + // TODO: Support multiple entry loops? (We currently bail out of these in // the IndVarSimplify pass) if (auto *BB = L->getLoopPredecessor()) { - Value *Incoming = PN->getIncomingValue(PN->getBasicBlockIndex(BB)); + Value *Incoming = PN->getIncomingValueForBlock(BB); const SCEV *IncomingS = SE->getSCEV(Incoming); - - if (!NewLHS && IncomingS == InvariantLHS) - NewLHS = Incoming; - if (!NewRHS && IncomingS == InvariantRHS) - NewRHS = Incoming; + CheapExpansions[IncomingS] = Incoming; } + Value *NewLHS = CheapExpansions[InvariantLHS]; + Value *NewRHS = CheapExpansions[InvariantRHS]; if (!NewLHS || !NewRHS) // We could not find an existing value to replace either LHS or RHS. |