1; RUN: opt -passes 'loop-reduce' -scalar-evolution-max-arith-depth=2 -S < %s | FileCheck %s
2; RUN: opt -loop-reduce -scalar-evolution-max-arith-depth=2 -S < %s | FileCheck %s
3
4; This test should just compile cleanly without assertions.
5
6target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
7
8define void @test(i32 %A, i32 %B, i32 %C) {
9; CHECK-LABEL: @test(
10; CHECK:       inner_loop:
11; CHECK-NEXT:    [[LSR_IV3:%.*]] = phi i32
12; CHECK-NEXT:    [[LSR_IV1:%.*]] = phi i32
13; CHECK-NEXT:    [[LSR_IV:%.*]] = phi i32
14; CHECK:         [[LSR_IV_NEXT:%.*]] = add i32 [[LSR_IV]], 3
15; CHECK-NEXT:    [[LSR_IV_NEXT2:%.*]] = add i32 [[LSR_IV1]], 3
16; CHECK-NEXT:    [[LSR_IV_NEXT4:%.*]] = add i32 [[LSR_IV3]], -3
17;
18entry:
19  br label %outer_loop
20
21outer_loop:
22  %phi2 = phi i32 [ %A, %entry ], [ 204, %outer_tail ]
23  %phi3 = phi i32 [ %A, %entry ], [ 243, %outer_tail ]
24  %phi4 = phi i32 [ %B, %entry ], [ %i35, %outer_tail ]
25  br label %guard
26
27guard:
28  %lcmp.mod = icmp eq i32 %C, 0
29  br i1 %lcmp.mod, label %outer_tail, label %preheader
30
31preheader:
32  %i15 = shl i32 %B, 1
33  br label %inner_loop
34
35inner_loop:
36  %phi5 = phi i32 [ %phi3, %preheader ], [ %i30, %inner_loop ]
37  %phi6 = phi i32 [ %phi2, %preheader ], [ %i33, %inner_loop ]
38  %iter = phi i32 [ %C, %preheader ], [ %iter.sub, %inner_loop ]
39  %i17 = sub i32 %phi4, %phi6
40  %i18 = sub i32 14, %phi5
41  %i19 = mul i32 %i18, %C
42  %factor.prol = shl i32 %phi5, 1
43  %i20 = add i32 %i17, %factor.prol
44  %i21 = add i32 %i20, %B
45  %i22 = add i32 %i21, %i19
46  %i23 = sub i32 14, %i22
47  %i24 = mul i32 %i23, %C
48  %factor.1.prol = shl i32 %i22, 1
49  %i25 = add i32 %i17, %factor.1.prol
50  %i27 = add i32 %i25, %i24
51  %i29 = mul i32 %i25, %C
52  %factor.2.prol = shl i32 %i27, 1
53  %i30 = add i32 %i17, %factor.2.prol
54  %i33 = add nsw i32 %phi6, -3
55  %iter.sub = add i32 %iter, -1
56  %iter.cmp = icmp eq i32 %iter.sub, 0
57  br i1 %iter.cmp, label %outer_tail, label %inner_loop
58
59outer_tail:
60  %phi7 = phi i32 [ %phi2, %guard ], [ %i33, %inner_loop ]
61  %i35 = sub i32 %A, %phi7
62  %cmp = icmp sgt i32 %i35, 9876
63  br i1 %cmp, label %exit, label %outer_loop
64
65exit:
66  ret void
67
68}
69