[llvm] r317012 - [IndVarSimplify] Simplify code using a dictionary
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 10:06:32 PDT 2017
Author: reames
Date: Tue Oct 31 10:06:32 2017
New Revision: 317012
URL: http://llvm.org/viewvc/llvm-project?rev=317012&view=rev
Log:
[IndVarSimplify] Simplify code using a dictionary
Possibly very slightly slower, but this code is not performance critical and the readability benefit alone is huge.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp?rev=317012&r1=317011&r2=317012&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp Tue Oct 31 10:06:32 2017
@@ -193,27 +193,19 @@ bool SimplifyIndvar::makeIVComparisonInv
// 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.
More information about the llvm-commits
mailing list