[PATCH] D35990: [SCEV] Prohibit SCEV transformations for huge SCEVs
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 14 22:56:53 PST 2019
mkazantsev updated this revision to Diff 181726.
mkazantsev added a comment.
Updated test to preserve current behavior (it creates *really* big SCEVs in test_05).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D35990/new/
https://reviews.llvm.org/D35990
Files:
lib/Analysis/ScalarEvolution.cpp
test/Transforms/LoopStrengthReduce/X86/bin_power.ll
Index: test/Transforms/LoopStrengthReduce/X86/bin_power.ll
===================================================================
--- test/Transforms/LoopStrengthReduce/X86/bin_power.ll
+++ test/Transforms/LoopStrengthReduce/X86/bin_power.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -loop-reduce -S | FileCheck %s
+; RUN: opt < %s -scalar-evolution-huge-expr-threshold=1000000 -loop-reduce -S | FileCheck %s
target datalayout = "e-m:e-i32:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -212,6 +212,11 @@
cl::desc("Max coefficients in AddRec during evolving"),
cl::init(8));
+static cl::opt<unsigned>
+ HugeExprThreshold("scalar-evolution-huge-expr-threshold", cl::Hidden,
+ cl::desc("Size of the expression which is considered huge"),
+ cl::init(4096));
+
//===----------------------------------------------------------------------===//
// SCEV class definitions
//===----------------------------------------------------------------------===//
@@ -850,6 +855,14 @@
return F.Size;
}
+static bool isHugeExpression(const SCEV *S) {
+ return S->getExpressionSize() >= HugeExprThreshold;
+}
+
+static bool hasHugeExpression(SmallVectorImpl<const SCEV *> &Ops) {
+ return any_of(Ops, isHugeExpression);
+}
+
namespace {
struct SCEVDivision : public SCEVVisitor<SCEVDivision, void> {
@@ -2409,7 +2422,7 @@
}
// Limit recursion calls depth.
- if (Depth > MaxArithDepth)
+ if (Depth > MaxArithDepth || hasHugeExpression(Ops))
return getOrCreateAddExpr(Ops, Flags);
// Okay, check to see if the same value occurs in the operand list more than
@@ -2888,7 +2901,7 @@
Flags = StrengthenNoWrapFlags(this, scMulExpr, Ops, Flags);
// Limit recursion calls depth.
- if (Depth > MaxArithDepth)
+ if (Depth > MaxArithDepth || hasHugeExpression(Ops))
return getOrCreateMulExpr(Ops, Flags);
// If there are any constants, fold them together.
@@ -3061,7 +3074,8 @@
// Limit max number of arguments to avoid creation of unreasonably big
// SCEVAddRecs with very complex operands.
if (AddRec->getNumOperands() + OtherAddRec->getNumOperands() - 1 >
- MaxAddRecSize)
+ MaxAddRecSize || isHugeExpression(AddRec) ||
+ isHugeExpression(OtherAddRec))
continue;
bool Overflow = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35990.181726.patch
Type: text/x-patch
Size: 2581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190115/b1ad2b63/attachment.bin>
More information about the llvm-commits
mailing list