[PATCH] D30552: Fix regressions cased by D29862
Evgeny Stupachenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 14:24:29 PST 2017
evstupac created this revision.
Herald added a subscriber: mzolotukhin.
The patch fix regressions in
Shootout-C++ matrix
and
spec2006/hmmer
caused by https://reviews.llvm.org/D29862.
Repository:
rL LLVM
https://reviews.llvm.org/D30552
Files:
lib/Transforms/Scalar/LoopStrengthReduce.cpp
test/Transforms/LoopStrengthReduce/2013-01-14-ReuseCast.ll
Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1074,10 +1074,10 @@
/// An enum for a kind of use, indicating what types of scaled and immediate
/// operands it might support.
enum KindType {
- Basic, ///< A normal use, with no folding.
- Special, ///< A special case of basic, allowing -1 scales.
- Address, ///< An address use; folding according to TargetLowering
- ICmpZero ///< An equality icmp with both operands folded into one.
+ Basic, ///< A normal use, with no folding.
+ ICmpZero, ///< An equality icmp with both operands folded into one.
+ Special, ///< A special case of basic, allowing -1 scales.
+ Address ///< An address use; folding according to TargetLowering
// TODO: Add a generic icmp too?
};
@@ -1522,6 +1522,11 @@
}
#endif
+static bool LSRUseCompare (const LSRUse &U1, const LSRUse &U2) {
+ return (U1.Kind < U2.Kind) ||
+ (U1.Kind == U2.Kind && U1.Formulae.size() < U2.Formulae.size());
+}
+
static bool isAMCompletelyFolded(const TargetTransformInfo &TTI,
LSRUse::KindType Kind, MemAccessTy AccessTy,
GlobalValue *BaseGV, int64_t BaseOffset,
@@ -4362,6 +4367,8 @@
// We can skip them in calculations.
SmallPtrSet<const SCEV *, 4> UniqRegs;
DEBUG(dbgs() << "The search space is too complex.\n");
+ // It is ok to sort Uses as we'll choose a solution in the function.
+ std::sort (Uses.begin(), Uses.end(), LSRUseCompare);
// Map each register to probability of not selecting
DenseMap <const SCEV *, float> RegNumMap;
@@ -4394,6 +4401,7 @@
// different results for different target builds.
float FMinRegNum = LU.Formulae[0].getNumRegs();
float FMinARegNum = LU.Formulae[0].getNumRegs();
+ unsigned FMinBaseAdd = LU.Formulae[0].getNumRegs();
size_t MinIdx = 0;
for (size_t i = 0, e = LU.Formulae.size(); i != e; ++i) {
Formula &F = LU.Formulae[i];
@@ -4417,9 +4425,12 @@
}
}
if (FMinRegNum > FRegNum ||
- (FMinRegNum == FRegNum && FMinARegNum > FARegNum)) {
+ (FMinRegNum == FRegNum &&
+ (FMinARegNum > FARegNum ||
+ (FMinARegNum == FARegNum && FMinBaseAdd > F.getNumRegs())))) {
FMinRegNum = FRegNum;
FMinARegNum = FARegNum;
+ FMinBaseAdd = F.getNumRegs();
MinIdx = i;
}
}
@@ -4432,7 +4443,6 @@
dbgs() << '\n');
LU.Formulae.pop_back();
}
- LU.RecomputeRegs(LUIdx, RegUses);
assert(LU.Formulae.size() == 1 && "Should be exactly 1 min regs formula");
Formula &F = LU.Formulae[0];
DEBUG(dbgs() << " Leaving only "; F.print(dbgs()); dbgs() << '\n');
Index: test/Transforms/LoopStrengthReduce/2013-01-14-ReuseCast.ll
===================================================================
--- test/Transforms/LoopStrengthReduce/2013-01-14-ReuseCast.ll
+++ test/Transforms/LoopStrengthReduce/2013-01-14-ReuseCast.ll
@@ -14,8 +14,8 @@
; current LSR cost model.
; CHECK-NOT: = ptrtoint i8* undef to i64
; CHECK: .lr.ph
-; CHECK: [[TMP:%[^ ]+]] = add i64 %4, 1
-; CHECK: sub i64 [[TMP]], %tmp6
+; CHECK: [[REG:%[^ ]+]] = add i64 %tmp6, -1
+; CHECK: sub i64 [[REG]], %tmp5
; CHECK: ret void
define void @VerifyDiagnosticConsumerTest() unnamed_addr nounwind uwtable align 2 {
bb:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30552.90394.patch
Type: text/x-patch
Size: 3507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170302/5f1b712b/attachment.bin>
More information about the llvm-commits
mailing list