llvm.org GIT mirror llvm / 3c09f0b
[SCEV] Add a threshold to restrict number of mul operands to be inlined into SCEV This is to avoid inlining too many multiplication operands into a SCEV, which could take exponential time in the worst case. Reviewers: Sanjoy Das, Mehdi Amini, Michael Zolotukhin Differential Revision: https://reviews.llvm.org/D25794 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284784 91177308-0d34-0410-b5e6-96231b3b80d8 Li Huang 3 years ago
2 changed file(s) with 36 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
120120 cl::desc("Verify no dangling value in ScalarEvolution's "
121121 "ExprValueMap (slow)"));
122122
123 static cl::opt MulOpsInlineThreshold(
124 "scev-mulops-inline-threshold", cl::Hidden,
125 cl::desc("Threshold for inlining multiplication operands into a SCEV"),
126 cl::init(1000));
127
123128 //===----------------------------------------------------------------------===//
124129 // SCEV class definitions
125130 //===----------------------------------------------------------------------===//
25152520 if (Idx < Ops.size()) {
25162521 bool DeletedMul = false;
25172522 while (const SCEVMulExpr *Mul = dyn_cast(Ops[Idx])) {
2523 if (Ops.size() > MulOpsInlineThreshold)
2524 break;
25182525 // If we have an mul, expand the mul operands onto the end of the operands
25192526 // list.
25202527 Ops.erase(Ops.begin()+Idx);
0 ; RUN: opt -analyze -scalar-evolution -scev-mulops-inline-threshold=1 < %s | FileCheck --check-prefix=CHECK1 %s
1 ; RUN: opt -analyze -scalar-evolution -scev-mulops-inline-threshold=10 < %s | FileCheck --check-prefix=CHECK10 %s
2
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 @a = local_unnamed_addr global i32 0, align 4
7 @b = local_unnamed_addr global i32 0, align 4
8
9 define i32 @main() local_unnamed_addr {
10
11 ; CHECK1: %mul.1 = mul nsw i32 %mul, %mul
12 ; CHECK1: --> ((%a.promoted * %a.promoted) * (%a.promoted * %a.promoted))
13
14 ; CHECK10: %mul.1 = mul nsw i32 %mul, %mul
15 ; CHECK10: --> (%a.promoted * %a.promoted * %a.promoted * %a.promoted)
16
17 entry:
18 %a.promoted = load i32, i32* @a, align 4
19 %mul = mul nsw i32 %a.promoted, %a.promoted
20 %mul.1 = mul nsw i32 %mul, %mul
21 %mul.2 = mul nsw i32 %mul.1, %mul.1
22 %mul.3 = mul nsw i32 %mul.2, %mul.2
23 %mul.4 = mul nsw i32 %mul.3, %mul.3
24 %mul.5 = mul nsw i32 %mul.4, %mul.4
25 store i32 %mul.5, i32* @a, align 4
26 store i32 31, i32* @b, align 4
27 ret i32 0
28 }