1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
3; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4
5target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
6target triple = "i386-pc-linux-gnu"
7
8@arr1 = internal unnamed_addr constant [50 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50], align 4
9@arr2 = internal unnamed_addr constant [50 x i32] [i32 49, i32 48, i32 47, i32 46, i32 45, i32 44, i32 43, i32 42, i32 41, i32 40, i32 39, i32 38, i32 37, i32 36, i32 35, i32 34, i32 33, i32 32, i32 31, i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0], align 4
10
11; PR11034
12define i32 @test1() nounwind readnone {
13; CHECK-LABEL: 'test1'
14; CHECK-NEXT:  Classifying expressions for: @test1
15; CHECK-NEXT:    %sum.04 = phi i32 [ 0, %entry ], [ %add2, %for.body ]
16; CHECK-NEXT:    --> %sum.04 U: full-set S: full-set Exits: 2450 LoopDispositions: { %for.body: Variant }
17; CHECK-NEXT:    %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
18; CHECK-NEXT:    --> {0,+,1}<nuw><nsw><%for.body> U: [0,50) S: [0,50) Exits: 49 LoopDispositions: { %for.body: Computable }
19; CHECK-NEXT:    %arrayidx = getelementptr inbounds [50 x i32], [50 x i32]* @arr1, i32 0, i32 %i.03
20; CHECK-NEXT:    --> {@arr1,+,4}<nuw><%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: (196 + @arr1) LoopDispositions: { %for.body: Computable }
21; CHECK-NEXT:    %0 = load i32, i32* %arrayidx, align 4
22; CHECK-NEXT:    --> %0 U: full-set S: full-set Exits: 50 LoopDispositions: { %for.body: Variant }
23; CHECK-NEXT:    %arrayidx1 = getelementptr inbounds [50 x i32], [50 x i32]* @arr2, i32 0, i32 %i.03
24; CHECK-NEXT:    --> {@arr2,+,4}<nuw><%for.body> U: [0,-3) S: [-2147483648,2147483645) Exits: (196 + @arr2) LoopDispositions: { %for.body: Computable }
25; CHECK-NEXT:    %1 = load i32, i32* %arrayidx1, align 4
26; CHECK-NEXT:    --> %1 U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Variant }
27; CHECK-NEXT:    %add = add i32 %0, %sum.04
28; CHECK-NEXT:    --> (%0 + %sum.04) U: full-set S: full-set Exits: 2500 LoopDispositions: { %for.body: Variant }
29; CHECK-NEXT:    %add2 = add i32 %add, %1
30; CHECK-NEXT:    --> (%1 + %0 + %sum.04) U: full-set S: full-set Exits: 2500 LoopDispositions: { %for.body: Variant }
31; CHECK-NEXT:    %inc = add nsw i32 %i.03, 1
32; CHECK-NEXT:    --> {1,+,1}<nuw><nsw><%for.body> U: [1,51) S: [1,51) Exits: 50 LoopDispositions: { %for.body: Computable }
33; CHECK-NEXT:  Determining loop execution counts for: @test1
34; CHECK-NEXT:  Loop %for.body: backedge-taken count is 49
35; CHECK-NEXT:  Loop %for.body: max backedge-taken count is 49
36; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is 49
37; CHECK-NEXT:   Predicates:
38; CHECK:       Loop %for.body: Trip multiple is 50
39;
40entry:
41  br label %for.body
42
43for.body:                                         ; preds = %entry, %for.body
44  %sum.04 = phi i32 [ 0, %entry ], [ %add2, %for.body ]
45  %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
46  %arrayidx = getelementptr inbounds [50 x i32], [50 x i32]* @arr1, i32 0, i32 %i.03
47  %0 = load i32, i32* %arrayidx, align 4
48  %arrayidx1 = getelementptr inbounds [50 x i32], [50 x i32]* @arr2, i32 0, i32 %i.03
49  %1 = load i32, i32* %arrayidx1, align 4
50  %add = add i32 %0, %sum.04
51  %add2 = add i32 %add, %1
52  %inc = add nsw i32 %i.03, 1
53  %cmp = icmp eq i32 %inc, 50
54  br i1 %cmp, label %for.end, label %for.body
55
56for.end:                                          ; preds = %for.body
57  ret i32 %add2
58}
59
60
61%struct.ListNode = type { %struct.ListNode*, i32 }
62
63@node5 = internal constant { %struct.ListNode*, i32, [4 x i8] } { %struct.ListNode* bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node4 to %struct.ListNode*), i32 4, [4 x i8] undef }, align 8
64@node4 = internal constant { %struct.ListNode*, i32, [4 x i8] } { %struct.ListNode* bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node3 to %struct.ListNode*), i32 3, [4 x i8] undef }, align 8
65@node3 = internal constant { %struct.ListNode*, i32, [4 x i8] } { %struct.ListNode* bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node2 to %struct.ListNode*), i32 2, [4 x i8] undef }, align 8
66@node2 = internal constant { %struct.ListNode*, i32, [4 x i8] } { %struct.ListNode* bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node1 to %struct.ListNode*), i32 1, [4 x i8] undef }, align 8
67@node1 = internal constant { %struct.ListNode*, i32, [4 x i8] } { %struct.ListNode* null, i32 0, [4 x i8] undef }, align 8
68
69define i32 @test2() nounwind uwtable readonly {
70; CHECK-LABEL: 'test2'
71; CHECK-NEXT:  Classifying expressions for: @test2
72; CHECK-NEXT:    %sum.02 = phi i32 [ 0, %entry ], [ %add, %for.body ]
73; CHECK-NEXT:    --> %sum.02 U: full-set S: full-set Exits: 10 LoopDispositions: { %for.body: Variant }
74; CHECK-NEXT:    %n.01 = phi %struct.ListNode* [ bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node5 to %struct.ListNode*), %entry ], [ %1, %for.body ]
75; CHECK-NEXT:    --> %n.01 U: full-set S: full-set Exits: @node1 LoopDispositions: { %for.body: Variant }
76; CHECK-NEXT:    %i = getelementptr inbounds %struct.ListNode, %struct.ListNode* %n.01, i64 0, i32 1
77; CHECK-NEXT:    --> (4 + %n.01)<nuw> U: [4,0) S: [4,0) Exits: (4 + @node1)<nuw><nsw> LoopDispositions: { %for.body: Variant }
78; CHECK-NEXT:    %0 = load i32, i32* %i, align 4
79; CHECK-NEXT:    --> %0 U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Variant }
80; CHECK-NEXT:    %add = add nsw i32 %0, %sum.02
81; CHECK-NEXT:    --> (%0 + %sum.02) U: full-set S: full-set Exits: 10 LoopDispositions: { %for.body: Variant }
82; CHECK-NEXT:    %next = getelementptr inbounds %struct.ListNode, %struct.ListNode* %n.01, i64 0, i32 0
83; CHECK-NEXT:    --> %n.01 U: full-set S: full-set Exits: @node1 LoopDispositions: { %for.body: Variant }
84; CHECK-NEXT:    %1 = load %struct.ListNode*, %struct.ListNode** %next, align 8
85; CHECK-NEXT:    --> %1 U: full-set S: full-set Exits: null LoopDispositions: { %for.body: Variant }
86; CHECK-NEXT:  Determining loop execution counts for: @test2
87; CHECK-NEXT:  Loop %for.body: backedge-taken count is 4
88; CHECK-NEXT:  Loop %for.body: max backedge-taken count is 4
89; CHECK-NEXT:  Loop %for.body: Predicated backedge-taken count is 4
90; CHECK-NEXT:   Predicates:
91; CHECK:       Loop %for.body: Trip multiple is 5
92;
93entry:
94  br label %for.body
95
96for.body:                                         ; preds = %entry, %for.body
97  %sum.02 = phi i32 [ 0, %entry ], [ %add, %for.body ]
98  %n.01 = phi %struct.ListNode* [ bitcast ({ %struct.ListNode*, i32, [4 x i8] }* @node5 to %struct.ListNode*), %entry ], [ %1, %for.body ]
99  %i = getelementptr inbounds %struct.ListNode, %struct.ListNode* %n.01, i64 0, i32 1
100  %0 = load i32, i32* %i, align 4
101  %add = add nsw i32 %0, %sum.02
102  %next = getelementptr inbounds %struct.ListNode, %struct.ListNode* %n.01, i64 0, i32 0
103  %1 = load %struct.ListNode*, %struct.ListNode** %next, align 8
104  %cmp = icmp eq %struct.ListNode* %1, null
105  br i1 %cmp, label %for.end, label %for.body
106
107for.end:                                          ; preds = %for.body
108  ret i32 %add
109}
110