1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4 ; Tests for smin & smax folds.
6 ; Test case from PR1614.
7 define i32 @test_PR1614(i32 %a, i32 %b, i32 %c) {
8 ; CHECK-LABEL: 'test_PR1614'
9 ; CHECK-NEXT: Classifying expressions for: @test_PR1614
10 ; CHECK-NEXT: %B = select i1 %A, i32 %a, i32 %b
11 ; CHECK-NEXT: --> (%a smax %b) U: full-set S: full-set
12 ; CHECK-NEXT: %D = select i1 %C, i32 %B, i32 %c
13 ; CHECK-NEXT: --> (%a smax %b smax %c) U: full-set S: full-set
14 ; CHECK-NEXT: Determining loop execution counts for: @test_PR1614
17 %A = icmp sgt i32 %a, %b
18 %B = select i1 %A, i32 %a, i32 %b
19 %C = icmp sle i32 %c, %B
20 %D = select i1 %C, i32 %B, i32 %c
24 declare void @iteration()
26 ; Test case from PR46939.
27 ; The information from the loop guard can be used to simplify the trip count expression.
28 define void @smin_simplify_with_guard(i32 %n) {
29 ; CHECK-LABEL: 'smin_simplify_with_guard'
30 ; CHECK-NEXT: Classifying expressions for: @smin_simplify_with_guard
31 ; CHECK-NEXT: %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
32 ; CHECK-NEXT: --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Computable }
33 ; CHECK-NEXT: %dec = add nsw i32 %i.011, -1
34 ; CHECK-NEXT: --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: -1 LoopDispositions: { %for.body: Computable }
35 ; CHECK-NEXT: Determining loop execution counts for: @smin_simplify_with_guard
36 ; CHECK-NEXT: Loop %for.body: backedge-taken count is %n
37 ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483647
38 ; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is %n
39 ; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is %n
40 ; CHECK-NEXT: Predicates:
41 ; CHECK-NEXT: Loop %for.body: Trip multiple is 1
44 %cmp10 = icmp sgt i32 %n, -1
45 br i1 %cmp10, label %for.body.lr.ph, label %for.cond.cleanup
51 %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
52 call void @iteration()
53 %dec = add nsw i32 %i.011, -1
54 %cmp = icmp sgt i32 %i.011, 0
55 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
57 for.cond.cleanup.loopexit:
58 br label %for.cond.cleanup
64 define void @smin_to_smax(i32 %n) {
65 ; FIXME: ((-1 * (0 smin %n)) + %n) is actually just (0 smax %n)
66 ; CHECK-LABEL: 'smin_to_smax'
67 ; CHECK-NEXT: Classifying expressions for: @smin_to_smax
68 ; CHECK-NEXT: %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
69 ; CHECK-NEXT: --> {%n,+,-1}<nsw><%for.body> U: full-set S: full-set Exits: (0 smin %n) LoopDispositions: { %for.body: Computable }
70 ; CHECK-NEXT: %dec = add nsw i32 %i.011, -1
71 ; CHECK-NEXT: --> {(-1 + %n),+,-1}<nw><%for.body> U: full-set S: full-set Exits: (-1 + (0 smin %n)) LoopDispositions: { %for.body: Computable }
72 ; CHECK-NEXT: Determining loop execution counts for: @smin_to_smax
73 ; CHECK-NEXT: Loop %for.body: backedge-taken count is ((-1 * (0 smin %n)) + %n)
74 ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483647
75 ; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is ((-1 * (0 smin %n)) + %n)
76 ; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is ((-1 * (0 smin %n)) + %n)
77 ; CHECK-NEXT: Predicates:
78 ; CHECK-NEXT: Loop %for.body: Trip multiple is 1
81 br label %for.body.lr.ph
87 %i.011 = phi i32 [ %n, %for.body.lr.ph ], [ %dec, %for.body ]
88 call void @iteration()
89 %dec = add nsw i32 %i.011, -1
90 %cmp = icmp sgt i32 %i.011, 0
91 br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit
93 for.cond.cleanup.loopexit:
94 br label %for.cond.cleanup
100 ; The information from the loop guard can be used to simplify the trip count expression.
101 define void @smax_simplify_with_guard(i32 %start, i32 %n) {
102 ; CHECK-LABEL: 'smax_simplify_with_guard'
103 ; CHECK-NEXT: Classifying expressions for: @smax_simplify_with_guard
104 ; CHECK-NEXT: %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]
105 ; CHECK-NEXT: --> {%start,+,1}<nsw><%loop> U: full-set S: full-set Exits: %n LoopDispositions: { %loop: Computable }
106 ; CHECK-NEXT: %inc.i = add nsw i32 %k.0.i26, 1
107 ; CHECK-NEXT: --> {(1 + %start),+,1}<nw><%loop> U: full-set S: full-set Exits: (1 + %n) LoopDispositions: { %loop: Computable }
108 ; CHECK-NEXT: Determining loop execution counts for: @smax_simplify_with_guard
109 ; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 * %start) + %n)
110 ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1
111 ; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is ((-1 * %start) + %n)
112 ; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 * %start) + %n)
113 ; CHECK-NEXT: Predicates:
114 ; CHECK-NEXT: Loop %loop: Trip multiple is 1
117 %guard = icmp sge i32 %n, %start
118 br i1 %guard, label %loop.ph, label %exit
124 %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]
125 %inc.i = add nsw i32 %k.0.i26, 1
126 %cmp26.not.i.not = icmp slt i32 %k.0.i26, %n
127 br i1 %cmp26.not.i.not, label %loop, label %exit