From 783633e29e0a24cfbb9a3d5bbf401b2bcbb212d7 Mon Sep 17 00:00:00 2001 From: Daniil Fukalov Date: Thu, 26 Jan 2017 13:33:17 +0000 Subject: [PATCH] [SCEV] Introduce add operation inlining limit Inlining in getAddExpr() can cause abnormal computational time in some cases. New parameter -scev-addops-inline-threshold is intruduced with default value 500. Reviewers: sanjoy Subscribers: mzolotukhin, llvm-commits Differential Revision: https://reviews.llvm.org/D28812 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293176 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 8 ++++++++ .../ScalarEvolution/max-addops-inline.ll | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/Analysis/ScalarEvolution/max-addops-inline.ll diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 18fcb0e85b6..ee09c8f3c01 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -127,6 +127,11 @@ static cl::opt MulOpsInlineThreshold( cl::desc("Threshold for inlining multiplication operands into a SCEV"), cl::init(1000)); +static cl::opt AddOpsInlineThreshold( + "scev-addops-inline-threshold", cl::Hidden, + cl::desc("Threshold for inlining multiplication operands into a SCEV"), + cl::init(500)); + static cl::opt MaxCompareDepth("scalar-evolution-max-compare-depth", cl::Hidden, cl::desc("Maximum depth of recursive compare complexity"), @@ -2219,6 +2224,9 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, if (Idx < Ops.size()) { bool DeletedAdd = false; while (const SCEVAddExpr *Add = dyn_cast(Ops[Idx])) { + if (Ops.size() > AddOpsInlineThreshold || + Add->getNumOperands() > AddOpsInlineThreshold) + break; // If we have an add, expand the add operands onto the end of the operands // list. Ops.erase(Ops.begin()+Idx); diff --git a/test/Analysis/ScalarEvolution/max-addops-inline.ll b/test/Analysis/ScalarEvolution/max-addops-inline.ll new file mode 100644 index 00000000000..2701ed32839 --- /dev/null +++ b/test/Analysis/ScalarEvolution/max-addops-inline.ll @@ -0,0 +1,17 @@ +; RUN: opt -analyze -scalar-evolution -scev-addops-inline-threshold=1 < %s | FileCheck --check-prefix=CHECK1 %s +; RUN: opt -analyze -scalar-evolution -scev-addops-inline-threshold=10 < %s | FileCheck --check-prefix=CHECK10 %s + +define i32 @foo(i64 %p0, i32 %p1) { +; CHECK1: %add2 = add nsw i32 %mul1, %add +; CHECK1-NEXT: --> ((trunc i64 %p0 to i32) * (1 + (trunc i64 %p0 to i32)) * (1 + %p1)) + +; CHECK10: %add2 = add nsw i32 %mul1, %add +; CHECK10-NEXT: --> ((trunc i64 %p0 to i32) * (1 + ((trunc i64 %p0 to i32) * (1 + %p1)) + %p1)) +entry: + %tr = trunc i64 %p0 to i32 + %mul = mul nsw i32 %tr, %p1 + %add = add nsw i32 %mul, %tr + %mul1 = mul nsw i32 %add, %tr + %add2 = add nsw i32 %mul1, %add + ret i32 %add2 +} -- 2.40.0