[PATCH] D19682: [LSR] Skip transformation if the cost of no LSR is cheaper than the best solution selected
Jun Bum Lim via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 28 12:55:03 PDT 2016
junbuml created this revision.
junbuml added reviewers: gberry, qcolombet, mcrosier.
junbuml added a subscriber: llvm-commits.
Herald added subscribers: mzolotukhin, mcrosier.
I'm posting this to get any early feedback. Please let me know if this make sense.
TODO: tests should be added.
http://reviews.llvm.org/D19682
Files:
lib/Transforms/Scalar/LoopStrengthReduce.cpp
Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1759,6 +1759,8 @@
DenseSet<const SCEV *> &VisitedRegs) const;
void Solve(SmallVectorImpl<const Formula *> &Solution) const;
+ bool IsNothingCheaperThanBestSolution(Cost BestCost) const;
+
BasicBlock::iterator
HoistInsertPosition(BasicBlock::iterator IP,
const SmallVectorImpl<Instruction *> &Inputs) const;
@@ -4211,6 +4213,25 @@
NarrowSearchSpaceByPickingWinnerRegs();
}
+bool LSRInstance::IsNothingCheaperThanBestSolution(Cost BestCost) const {
+ DenseSet<const SCEV *> VisitedRegs;
+ SmallPtrSet<const SCEV *, 16> Regs;
+ Cost BaseCost;
+
+ for (const LSRFixup &LF : Fixups) {
+ const SCEV *S = SE.getSCEV(LF.OperandValToReplace);
+ Formula F;
+ F.initialMatch(S, L, SE);
+
+ const LSRUse &LU = Uses[LF.LUIdx];
+ BaseCost.RateFormula(TTI, F, Regs, VisitedRegs, L, LU.Offsets, SE, DT, LU);
+ if (BestCost < BaseCost)
+ return false;
+ }
+ return (BaseCost < BestCost);
+}
+
+
/// This is the recursive solver.
void LSRInstance::SolveRecurse(SmallVectorImpl<const Formula *> &Solution,
Cost &SolutionCost,
@@ -4306,6 +4327,10 @@
if (Solution.empty()) {
DEBUG(dbgs() << "\nNo Satisfactory Solution\n");
return;
+ } else if (IsNothingCheaperThanBestSolution(SolutionCost)) {
+ DEBUG(dbgs() << "\nThe best solution is not cheaper than no LSR\n");
+ Solution.clear();
+ return;
}
// Ok, we've now made all our decisions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19682.55463.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160428/114a0780/attachment.bin>
More information about the llvm-commits
mailing list