[PATCH] D26389: [SCEV] limit recursion depth of CompareSCEVComplexity
Daniil Fukalov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 9 02:08:15 PST 2016
dfukalov updated this revision to Diff 77322.
Herald added a subscriber: mzolotukhin.
https://reviews.llvm.org/D26389
Files:
lib/Analysis/ScalarEvolution.cpp
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -127,6 +127,11 @@
cl::desc("Threshold for inlining multiplication operands into a SCEV"),
cl::init(1000));
+static cl::opt<unsigned>
+ MaxCompareDepth("scalar-evolution-max-compare-depth", cl::Hidden,
+ cl::desc("Maximum depth of recursive compare complexity"),
+ cl::init(10));
+
//===----------------------------------------------------------------------===//
// SCEV class definitions
//===----------------------------------------------------------------------===//
@@ -551,7 +556,7 @@
// than RHS, respectively. A three-way result allows recursive comparisons to be
// more efficient.
static int CompareSCEVComplexity(const LoopInfo *const LI, const SCEV *LHS,
- const SCEV *RHS) {
+ const SCEV *RHS, unsigned Depth = 0) {
// Fast-path: SCEVs are uniqued so we can do a quick equality check.
if (LHS == RHS)
return 0;
@@ -561,6 +566,10 @@
if (LType != RType)
return (int)LType - (int)RType;
+ // Limit recursion depth
+ if (Depth > MaxCompareDepth)
+ return 0;
+
// Aside from the getSCEVType() ordering, the particular ordering
// isn't very important except that it's beneficial to be consistent,
// so that (a + b) and (b + a) don't end up as different expressions.
@@ -605,7 +614,8 @@
// Lexicographically compare.
for (unsigned i = 0; i != LNumOps; ++i) {
- long X = CompareSCEVComplexity(LI, LA->getOperand(i), RA->getOperand(i));
+ long X = CompareSCEVComplexity(LI, LA->getOperand(i), RA->getOperand(i),
+ Depth + 1);
if (X != 0)
return X;
}
@@ -628,7 +638,8 @@
for (unsigned i = 0; i != LNumOps; ++i) {
if (i >= RNumOps)
return 1;
- long X = CompareSCEVComplexity(LI, LC->getOperand(i), RC->getOperand(i));
+ long X = CompareSCEVComplexity(LI, LC->getOperand(i), RC->getOperand(i),
+ Depth + 1);
if (X != 0)
return X;
}
@@ -640,10 +651,10 @@
const SCEVUDivExpr *RC = cast<SCEVUDivExpr>(RHS);
// Lexicographically compare udiv expressions.
- long X = CompareSCEVComplexity(LI, LC->getLHS(), RC->getLHS());
+ long X = CompareSCEVComplexity(LI, LC->getLHS(), RC->getLHS(), Depth + 1);
if (X != 0)
return X;
- return CompareSCEVComplexity(LI, LC->getRHS(), RC->getRHS());
+ return CompareSCEVComplexity(LI, LC->getRHS(), RC->getRHS(), Depth + 1);
}
case scTruncate:
@@ -653,7 +664,7 @@
const SCEVCastExpr *RC = cast<SCEVCastExpr>(RHS);
// Compare cast expressions by operand.
- return CompareSCEVComplexity(LI, LC->getOperand(), RC->getOperand());
+ return CompareSCEVComplexity(LI, LC->getOperand(), RC->getOperand(), Depth + 1);
}
case scCouldNotCompute:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26389.77322.patch
Type: text/x-patch
Size: 3072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161109/37c30b90/attachment.bin>
More information about the llvm-commits
mailing list