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
5 ; Tests for smin & smax folds.
7 ; Test case from PR1614.
8 define i32 @test_PR1614(i32 %a, i32 %b, i32 %c) {
9 ; CHECK-LABEL: 'test_PR1614'
10 ; CHECK: --> (%a smax %b)
11 ; CHECK: --> (%a smax %b smax %c)
14 %A = icmp sgt i32 %a, %b
15 %B = select i1 %A, i32 %a, i32 %b
16 %C = icmp sle i32 %c, %B
17 %D = select i1 %C, i32 %B, i32 %c
21 declare void @iteration()
23 ; Test case from PR46939.
24 ; The information from the loop guard can be used to simplify the trip count expression.
25 define void @smin_simplify_with_guard(i32 %n) {
26 ; CHECK-LABEL: 'smin_simplify_with_guard'
27 ; CHECK-NEXT: Classifying expressions for: @smin_simplify_with_guard
28 ; CHECK-NEXT: %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
29 ; CHECK-NEXT: --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Computable }
30 ; CHECK-NEXT: %dec = add nsw i32 %i.011, -1
31 ; CHECK-NEXT: --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: -1 LoopDispositions: { %for.body: Computable }
32 ; CHECK-NEXT: Determining loop execution counts for: @smin_simplify_with_guard
33 ; CHECK-NEXT: Loop %for.body: backedge-taken count is %n
34 ; CHECK-NEXT: Loop %for.body: max backedge-taken count is 2147483647
35 ; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is %n
36 ; CHECK-NEXT: Predicates:
37 ; CHECK: Loop %for.body: Trip multiple is 1
40 %cmp10 = icmp sgt i32 %n, -1
41 br i1 %cmp10, label %for.body.lr.ph, label %for.cond.cleanup
47 %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
48 call void @iteration()
49 %dec = add nsw i32 %i.011, -1
50 %cmp = icmp sgt i32 %i.011, 0
51 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
53 for.cond.cleanup.loopexit:
54 br label %for.cond.cleanup
60 define void @smin_to_smax(i32 %n) {
61 ; FIXME: ((-1 * (0 smin %n)) + %n) is actually just (0 smax %n)
63 ; CHECK-LABEL: 'smin_to_smax'
64 ; CHECK-NEXT: Classifying expressions for: @smin_to_smax
65 ; CHECK-NEXT: %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
66 ; CHECK-NEXT: --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: (0 smin %n) LoopDispositions: { %for.body: Computable }
67 ; CHECK-NEXT: %dec = add nsw i32 %i.011, -1
68 ; CHECK-NEXT: --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: (-1 + (0 smin %n)) LoopDispositions: { %for.body: Computable }
69 ; CHECK-NEXT: Determining loop execution counts for: @smin_to_smax
70 ; CHECK-NEXT: Loop %for.body: backedge-taken count is ((-1 * (0 smin %n)) + %n)
71 ; CHECK-NEXT: Loop %for.body: max backedge-taken count is 2147483647
72 ; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is ((-1 * (0 smin %n)) + %n)
73 ; CHECK-NEXT: Predicates:
74 ; CHECK: Loop %for.body: Trip multiple is 1
77 br label %for.body.lr.ph
83 %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
84 call void @iteration()
85 %dec = add nsw i32 %i.011, -1
86 %cmp = icmp sgt i32 %i.011, 0
87 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
89 for.cond.cleanup.loopexit:
90 br label %for.cond.cleanup
96 ; The information from the loop guard can be used to simplify the trip count expression.
97 define void @smax_simplify_with_guard(i32 %start, i32 %n) {
98 ; CHECK-LABEL: 'smax_simplify_with_guard'
99 ; CHECK-NEXT: Classifying expressions for: @smax_simplify_with_guard
100 ; CHECK-NEXT: %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]
101 ; CHECK-NEXT: --> {%start,+,1}<nsw><%loop> U: full-set S: full-set Exits: %n LoopDispositions: { %loop: Computable }
102 ; CHECK-NEXT: %inc.i = add nsw i32 %k.0.i26, 1
103 ; CHECK-NEXT: --> {(1 + %start),+,1}<nw><%loop> U: full-set S: full-set Exits: (1 + %n) LoopDispositions: { %loop: Computable }
104 ; CHECK-NEXT: Determining loop execution counts for: @smax_simplify_with_guard
105 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + %n)
106 ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1
107 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 * %start) + %n)
108 ; CHECK-NEXT: Predicates:
109 ; CHECK: Loop %loop: Trip multiple is 1
111 %guard = icmp sge i32 %n, %start
112 br i1 %guard, label %loop.ph, label %exit
118 %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]
119 %inc.i = add nsw i32 %k.0.i26, 1
120 %cmp26.not.i.not = icmp slt i32 %k.0.i26, %n
121 br i1 %cmp26.not.i.not, label %loop, label %exit