xref: /llvm-project/llvm/test/Analysis/ScalarEvolution/exit-count-select-safe.ll (revision 76a0abbc13cdfd3ae71f8db8a9376f65a9f6f725)
16a563e25SRoman Lebedev; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
26a563e25SRoman Lebedev; RUN: opt -disable-output "-passes=print<scalar-evolution>" %s 2>&1 | FileCheck %s
36a563e25SRoman Lebedev
46a563e25SRoman Lebedevdefine i32 @logical_and_2ops(i32 %n, i32 %m) {
56a563e25SRoman Lebedev; CHECK-LABEL: 'logical_and_2ops'
66a563e25SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_and_2ops
76a563e25SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
8*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %m) LoopDispositions: { %loop: Computable }
96a563e25SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
10*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %m)) LoopDispositions: { %loop: Computable }
116a563e25SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p0, i1 %cond_p1, i1 false
126a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
136a563e25SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_and_2ops
14*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %m)
156a563e25SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
16*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %m)
1782fb4f4bSRoman Lebedev; CHECK-NEXT:   Predicates:
1882fb4f4bSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
196a563e25SRoman Lebedev;
206a563e25SRoman Lebedeventry:
216a563e25SRoman Lebedev  br label %loop
226a563e25SRoman Lebedevloop:
236a563e25SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
246a563e25SRoman Lebedev  %i.next = add i32 %i, 1
256a563e25SRoman Lebedev  %cond_p0 = icmp ult i32 %i, %n
266a563e25SRoman Lebedev  %cond_p1 = icmp ult i32 %i, %m
276a563e25SRoman Lebedev  %cond = select i1 %cond_p0, i1 %cond_p1, i1 false
286a563e25SRoman Lebedev  br i1 %cond, label %loop, label %exit
296a563e25SRoman Lebedevexit:
306a563e25SRoman Lebedev  ret i32 %i
316a563e25SRoman Lebedev}
326a563e25SRoman Lebedev
336a563e25SRoman Lebedevdefine i32 @logical_or_2ops(i32 %n, i32 %m) {
346a563e25SRoman Lebedev; CHECK-LABEL: 'logical_or_2ops'
356a563e25SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_2ops
366a563e25SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
37*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %m) LoopDispositions: { %loop: Computable }
386a563e25SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
39*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %m)) LoopDispositions: { %loop: Computable }
406a563e25SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p0, i1 true, i1 %cond_p1
416a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
426a563e25SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_2ops
43*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %m)
446a563e25SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
45*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %m)
4682fb4f4bSRoman Lebedev; CHECK-NEXT:   Predicates:
4782fb4f4bSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
486a563e25SRoman Lebedev;
496a563e25SRoman Lebedeventry:
506a563e25SRoman Lebedev  br label %loop
516a563e25SRoman Lebedevloop:
526a563e25SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
536a563e25SRoman Lebedev  %i.next = add i32 %i, 1
546a563e25SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %n
556a563e25SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %m
566a563e25SRoman Lebedev  %cond = select i1 %cond_p0, i1 true, i1 %cond_p1
576a563e25SRoman Lebedev  br i1 %cond, label %exit, label %loop
586a563e25SRoman Lebedevexit:
596a563e25SRoman Lebedev  ret i32 %i
606a563e25SRoman Lebedev}
616a563e25SRoman Lebedev
626a563e25SRoman Lebedevdefine i32 @logical_and_3ops(i32 %n, i32 %m, i32 %k) {
636a563e25SRoman Lebedev; CHECK-LABEL: 'logical_and_3ops'
646a563e25SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_and_3ops
656a563e25SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
66*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %m umin_seq %k) LoopDispositions: { %loop: Computable }
676a563e25SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
68*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %m umin_seq %k)) LoopDispositions: { %loop: Computable }
696a563e25SRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 %cond_p1, i1 false
706a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
716a563e25SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 %cond_p2, i1 false
726a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
736a563e25SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_and_3ops
74*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %m umin_seq %k)
756a563e25SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
76*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %m umin_seq %k)
7782fb4f4bSRoman Lebedev; CHECK-NEXT:   Predicates:
7882fb4f4bSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
796a563e25SRoman Lebedev;
806a563e25SRoman Lebedeventry:
816a563e25SRoman Lebedev  br label %loop
826a563e25SRoman Lebedevloop:
836a563e25SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
846a563e25SRoman Lebedev  %i.next = add i32 %i, 1
856a563e25SRoman Lebedev  %cond_p0 = icmp ult i32 %i, %n
866a563e25SRoman Lebedev  %cond_p1 = icmp ult i32 %i, %m
876a563e25SRoman Lebedev  %cond_p2 = icmp ult i32 %i, %k
886a563e25SRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 %cond_p1, i1 false
896a563e25SRoman Lebedev  %cond = select i1 %cond_p3, i1 %cond_p2, i1 false
906a563e25SRoman Lebedev  br i1 %cond, label %loop, label %exit
916a563e25SRoman Lebedevexit:
926a563e25SRoman Lebedev  ret i32 %i
936a563e25SRoman Lebedev}
946a563e25SRoman Lebedev
956a563e25SRoman Lebedevdefine i32 @logical_or_3ops(i32 %n, i32 %m, i32 %k) {
966a563e25SRoman Lebedev; CHECK-LABEL: 'logical_or_3ops'
976a563e25SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops
986a563e25SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
99*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %m umin_seq %k) LoopDispositions: { %loop: Computable }
1006a563e25SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
101*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %m umin_seq %k)) LoopDispositions: { %loop: Computable }
1026a563e25SRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
1036a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
1046a563e25SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
1056a563e25SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
1066a563e25SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops
107*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %m umin_seq %k)
1086a563e25SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
109*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %m umin_seq %k)
11082fb4f4bSRoman Lebedev; CHECK-NEXT:   Predicates:
11182fb4f4bSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
1126a563e25SRoman Lebedev;
1136a563e25SRoman Lebedeventry:
1146a563e25SRoman Lebedev  br label %loop
1156a563e25SRoman Lebedevloop:
1166a563e25SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
1176a563e25SRoman Lebedev  %i.next = add i32 %i, 1
1186a563e25SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %n
1196a563e25SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %m
1206a563e25SRoman Lebedev  %cond_p2 = icmp uge i32 %i, %k
1216a563e25SRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
1226a563e25SRoman Lebedev  %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
1236a563e25SRoman Lebedev  br i1 %cond, label %exit, label %loop
1246a563e25SRoman Lebedevexit:
1256a563e25SRoman Lebedev  ret i32 %i
1266a563e25SRoman Lebedev}
127e0772cf0SRoman Lebedev
128e0772cf0SRoman Lebedevdefine i32 @computeSCEVAtScope(i32 %d.0) {
129e0772cf0SRoman Lebedev; CHECK-LABEL: 'computeSCEVAtScope'
130e0772cf0SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @computeSCEVAtScope
131e0772cf0SRoman Lebedev; CHECK-NEXT:    %d.1 = phi i32 [ %inc, %for.body ], [ %d.0, %for.cond.preheader ]
132*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {%d.0,+,1}<nsw><%for.cond> U: full-set S: full-set Exits: (((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
133e0772cf0SRoman Lebedev; CHECK-NEXT:    %e.1 = phi i32 [ %inc3, %for.body ], [ %d.0, %for.cond.preheader ]
134*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {%d.0,+,1}<nsw><%for.cond> U: full-set S: full-set Exits: (((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
135e0772cf0SRoman Lebedev; CHECK-NEXT:    %0 = select i1 %tobool1, i1 %tobool2, i1 false
136*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> %0 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant, %while.cond: Variant }
137e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc = add nsw i32 %d.1, 1
138*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {(1 + %d.0),+,1}<nw><%for.cond> U: full-set S: full-set Exits: (1 + ((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
139e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc3 = add nsw i32 %e.1, 1
140*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {(1 + %d.0),+,1}<nw><%for.cond> U: full-set S: full-set Exits: (1 + ((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
141e0772cf0SRoman Lebedev; CHECK-NEXT:    %f.1 = phi i32 [ %inc8, %for.body5 ], [ 0, %for.cond4.preheader ]
142*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%for.cond4> U: full-set S: full-set Exits: (((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond4: Computable, %while.cond: Variant }
143e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc8 = add i32 %f.1, 1
144*76a0abbcSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%for.cond4> U: full-set S: full-set Exits: (1 + ((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0) LoopDispositions: { %for.cond4: Computable, %while.cond: Variant }
145e0772cf0SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @computeSCEVAtScope
146*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %for.cond: backedge-taken count is ((-1 * %d.0) umin_seq (-1 * %d.0))
147e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %for.cond: max backedge-taken count is -1
148*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %for.cond: Predicated backedge-taken count is ((-1 * %d.0) umin_seq (-1 * %d.0))
149e0772cf0SRoman Lebedev; CHECK-NEXT:   Predicates:
150e0772cf0SRoman Lebedev; CHECK:       Loop %for.cond: Trip multiple is 1
151*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: backedge-taken count is (((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0)
152*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: max backedge-taken count is -1
153*76a0abbcSRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: Predicated backedge-taken count is (((-1 * %d.0) umin_seq (-1 * %d.0)) + %d.0)
154e0772cf0SRoman Lebedev; CHECK-NEXT:   Predicates:
155e0772cf0SRoman Lebedev; CHECK:       Loop %for.cond4: Trip multiple is 1
156e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: <multiple exits> Unpredictable backedge-taken count.
157e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: Unpredictable max backedge-taken count.
158e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: Unpredictable predicated backedge-taken count.
159e0772cf0SRoman Lebedev;
160e0772cf0SRoman Lebedeventry:
161e0772cf0SRoman Lebedev  br label %while.cond
162e0772cf0SRoman Lebedev
163e0772cf0SRoman Lebedevwhile.cond.loopexit:                              ; preds = %for.cond4
164e0772cf0SRoman Lebedev  br label %while.cond
165e0772cf0SRoman Lebedev
166e0772cf0SRoman Lebedevwhile.cond:                                       ; preds = %while.cond.loopexit, %entry
167e0772cf0SRoman Lebedev  br label %for.cond.preheader
168e0772cf0SRoman Lebedev
169e0772cf0SRoman Lebedevfor.cond.preheader:                               ; preds = %while.cond
170e0772cf0SRoman Lebedev  br label %for.cond
171e0772cf0SRoman Lebedev
172e0772cf0SRoman Lebedevfor.cond:                                         ; preds = %for.body, %for.cond.preheader
173e0772cf0SRoman Lebedev  %d.1 = phi i32 [ %inc, %for.body ], [ %d.0, %for.cond.preheader ]
174e0772cf0SRoman Lebedev  %e.1 = phi i32 [ %inc3, %for.body ], [ %d.0, %for.cond.preheader ]
175e0772cf0SRoman Lebedev  %tobool1 = icmp ne i32 %e.1, 0
176e0772cf0SRoman Lebedev  %tobool2 = icmp ne i32 %d.1, 0
177e0772cf0SRoman Lebedev  %0 = select i1 %tobool1, i1 %tobool2, i1 false
178e0772cf0SRoman Lebedev  br i1 %0, label %for.body, label %for.cond4.preheader
179e0772cf0SRoman Lebedev
180e0772cf0SRoman Lebedevfor.cond4.preheader:                              ; preds = %for.cond
181e0772cf0SRoman Lebedev  br label %for.cond4
182e0772cf0SRoman Lebedev
183e0772cf0SRoman Lebedevfor.body:                                         ; preds = %for.cond
184e0772cf0SRoman Lebedev  %inc = add nsw i32 %d.1, 1
185e0772cf0SRoman Lebedev  %inc3 = add nsw i32 %e.1, 1
186e0772cf0SRoman Lebedev  br label %for.cond
187e0772cf0SRoman Lebedev
188e0772cf0SRoman Lebedevfor.cond4:                                        ; preds = %for.body5, %for.cond4.preheader
189e0772cf0SRoman Lebedev  %f.1 = phi i32 [ %inc8, %for.body5 ], [ 0, %for.cond4.preheader ]
190e0772cf0SRoman Lebedev  %exitcond.not = icmp eq i32 %f.1, %e.1
191e0772cf0SRoman Lebedev  br i1 %exitcond.not, label %while.cond.loopexit, label %for.body5
192e0772cf0SRoman Lebedev
193e0772cf0SRoman Lebedevfor.body5:                                        ; preds = %for.cond4
194e0772cf0SRoman Lebedev  %inc8 = add i32 %f.1, 1
195e0772cf0SRoman Lebedev  br label %for.cond4
196e0772cf0SRoman Lebedev}
197