[llvm] r293176 - [SCEV] Introduce add operation inlining limit

Daniil Fukalov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 05:33:18 PST 2017


Author: dfukalov
Date: Thu Jan 26 07:33:17 2017
New Revision: 293176

URL: http://llvm.org/viewvc/llvm-project?rev=293176&view=rev
Log:
[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

Added:
    llvm/trunk/test/Analysis/ScalarEvolution/max-addops-inline.ll
Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=293176&r1=293175&r2=293176&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu Jan 26 07:33:17 2017
@@ -127,6 +127,11 @@ static cl::opt<unsigned> MulOpsInlineThr
     cl::desc("Threshold for inlining multiplication operands into a SCEV"),
     cl::init(1000));
 
+static cl::opt<unsigned> AddOpsInlineThreshold(
+    "scev-addops-inline-threshold", cl::Hidden,
+    cl::desc("Threshold for inlining multiplication operands into a SCEV"),
+    cl::init(500));
+
 static cl::opt<unsigned>
     MaxCompareDepth("scalar-evolution-max-compare-depth", cl::Hidden,
                     cl::desc("Maximum depth of recursive compare complexity"),
@@ -2219,6 +2224,9 @@ const SCEV *ScalarEvolution::getAddExpr(
   if (Idx < Ops.size()) {
     bool DeletedAdd = false;
     while (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(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);

Added: llvm/trunk/test/Analysis/ScalarEvolution/max-addops-inline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/max-addops-inline.ll?rev=293176&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/max-addops-inline.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/max-addops-inline.ll Thu Jan 26 07:33:17 2017
@@ -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
+}




More information about the llvm-commits mailing list