xref: /llvm-project/llvm/test/Analysis/ScalarEvolution/exit-count-select-safe.ll (revision 5ceb070bbbe3a58870dce811bf8f9e9ec1438d72)
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 ]
876a0abbcSRoman 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
1076a0abbcSRoman 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
1476a0abbcSRoman 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
1676a0abbcSRoman 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 ]
3776a0abbcSRoman 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
3976a0abbcSRoman 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
4376a0abbcSRoman 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
4576a0abbcSRoman 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 ]
6676a0abbcSRoman 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
6876a0abbcSRoman 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
7476a0abbcSRoman 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
7676a0abbcSRoman 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 ]
9976a0abbcSRoman 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
10176a0abbcSRoman 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
10776a0abbcSRoman 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
10976a0abbcSRoman 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
12836075942SRoman Lebedevdefine i32 @logical_or_3ops_duplicate(i32 %n, i32 %m, i32 %k) {
12936075942SRoman Lebedev; CHECK-LABEL: 'logical_or_3ops_duplicate'
13036075942SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops_duplicate
13136075942SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
1325e166507SRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %m umin_seq %k) LoopDispositions: { %loop: Computable }
13336075942SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
1345e166507SRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %m umin_seq %k)) LoopDispositions: { %loop: Computable }
13536075942SRoman Lebedev; CHECK-NEXT:    %cond_p4 = select i1 %cond_p0, i1 true, i1 %cond_p1
13636075942SRoman Lebedev; CHECK-NEXT:    --> %cond_p4 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
13736075942SRoman Lebedev; CHECK-NEXT:    %cond_p5 = select i1 %cond_p4, i1 true, i1 %cond_p2
13836075942SRoman Lebedev; CHECK-NEXT:    --> %cond_p5 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
13936075942SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p5, i1 true, i1 %cond_p3
14036075942SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
14136075942SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops_duplicate
1425e166507SRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %m umin_seq %k)
14336075942SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
1445e166507SRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %m umin_seq %k)
14536075942SRoman Lebedev; CHECK-NEXT:   Predicates:
14636075942SRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
14736075942SRoman Lebedev;
14836075942SRoman Lebedeventry:
14936075942SRoman Lebedev  br label %loop
15036075942SRoman Lebedevloop:
15136075942SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
15236075942SRoman Lebedev  %i.next = add i32 %i, 1
15336075942SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %n
15436075942SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %m
15536075942SRoman Lebedev  %cond_p2 = icmp uge i32 %i, %n
15636075942SRoman Lebedev  %cond_p3 = icmp uge i32 %i, %k
15736075942SRoman Lebedev  %cond_p4 = select i1 %cond_p0, i1 true, i1 %cond_p1
15836075942SRoman Lebedev  %cond_p5 = select i1 %cond_p4, i1 true, i1 %cond_p2
15936075942SRoman Lebedev  %cond = select i1 %cond_p5, i1 true, i1 %cond_p3
16036075942SRoman Lebedev  br i1 %cond, label %exit, label %loop
16136075942SRoman Lebedevexit:
16236075942SRoman Lebedev  ret i32 %i
16336075942SRoman Lebedev}
16436075942SRoman Lebedev
165138d5c75SRoman Lebedevdefine i32 @logical_or_3ops_redundant_uminseq_operand(i32 %n, i32 %m, i32 %k) {
166138d5c75SRoman Lebedev; CHECK-LABEL: 'logical_or_3ops_redundant_uminseq_operand'
167138d5c75SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops_redundant_uminseq_operand
168138d5c75SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
169*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: ((%n umin %m) umin_seq %k) LoopDispositions: { %loop: Computable }
170138d5c75SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
171*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + ((%n umin %m) umin_seq %k)) LoopDispositions: { %loop: Computable }
172138d5c75SRoman Lebedev; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
173138d5c75SRoman Lebedev; CHECK-NEXT:    --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
174138d5c75SRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
175138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
176138d5c75SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
177138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
178138d5c75SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops_redundant_uminseq_operand
179*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is ((%n umin %m) umin_seq %k)
180138d5c75SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
181*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((%n umin %m) umin_seq %k)
182138d5c75SRoman Lebedev; CHECK-NEXT:   Predicates:
183138d5c75SRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
184138d5c75SRoman Lebedev;
185138d5c75SRoman Lebedeventry:
186138d5c75SRoman Lebedev  br label %loop
187138d5c75SRoman Lebedevloop:
188138d5c75SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
189138d5c75SRoman Lebedev  %i.next = add i32 %i, 1
190138d5c75SRoman Lebedev  %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
191138d5c75SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %umin
192138d5c75SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %n
193138d5c75SRoman Lebedev  %cond_p2 = icmp uge i32 %i, %k
194138d5c75SRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
195138d5c75SRoman Lebedev  %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
196138d5c75SRoman Lebedev  br i1 %cond, label %exit, label %loop
197138d5c75SRoman Lebedevexit:
198138d5c75SRoman Lebedev  ret i32 %i
199138d5c75SRoman Lebedev}
200138d5c75SRoman Lebedev
201138d5c75SRoman Lebedevdefine i32 @logical_or_3ops_redundant_umin_operand(i32 %n, i32 %m, i32 %k) {
202138d5c75SRoman Lebedev; CHECK-LABEL: 'logical_or_3ops_redundant_umin_operand'
203138d5c75SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops_redundant_umin_operand
204138d5c75SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
205*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq %k umin_seq %m) LoopDispositions: { %loop: Computable }
206138d5c75SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
207*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq %k umin_seq %m)) LoopDispositions: { %loop: Computable }
208138d5c75SRoman Lebedev; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
209138d5c75SRoman Lebedev; CHECK-NEXT:    --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
210138d5c75SRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
211138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
212138d5c75SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
213138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
214138d5c75SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops_redundant_umin_operand
215*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq %k umin_seq %m)
216138d5c75SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
217*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq %k umin_seq %m)
218138d5c75SRoman Lebedev; CHECK-NEXT:   Predicates:
219138d5c75SRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
220138d5c75SRoman Lebedev;
221138d5c75SRoman Lebedeventry:
222138d5c75SRoman Lebedev  br label %loop
223138d5c75SRoman Lebedevloop:
224138d5c75SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
225138d5c75SRoman Lebedev  %i.next = add i32 %i, 1
226138d5c75SRoman Lebedev  %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
227138d5c75SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %n
228138d5c75SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %k
229138d5c75SRoman Lebedev  %cond_p2 = icmp uge i32 %i, %umin
230138d5c75SRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
231138d5c75SRoman Lebedev  %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
232138d5c75SRoman Lebedev  br i1 %cond, label %exit, label %loop
233138d5c75SRoman Lebedevexit:
234138d5c75SRoman Lebedev  ret i32 %i
235138d5c75SRoman Lebedev}
236b2be7dcfSRoman Lebedev
237138d5c75SRoman Lebedevdefine i32 @logical_or_4ops_redundant_operand_across_umins(i32 %n, i32 %m, i32 %k, i32 %q) {
238138d5c75SRoman Lebedev; CHECK-LABEL: 'logical_or_4ops_redundant_operand_across_umins'
239138d5c75SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_4ops_redundant_operand_across_umins
240138d5c75SRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
241*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: ((%n umin %m) umin_seq %k umin_seq %q) LoopDispositions: { %loop: Computable }
242138d5c75SRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
243*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + ((%n umin %m) umin_seq %k umin_seq %q)) LoopDispositions: { %loop: Computable }
244138d5c75SRoman Lebedev; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
245138d5c75SRoman Lebedev; CHECK-NEXT:    --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
246138d5c75SRoman Lebedev; CHECK-NEXT:    %umin2 = call i32 @llvm.umin.i32(i32 %n, i32 %q)
247138d5c75SRoman Lebedev; CHECK-NEXT:    --> (%n umin %q) U: full-set S: full-set Exits: (%n umin %q) LoopDispositions: { %loop: Invariant }
248138d5c75SRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
249138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
250138d5c75SRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
251138d5c75SRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
252138d5c75SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_4ops_redundant_operand_across_umins
253*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is ((%n umin %m) umin_seq %k umin_seq %q)
254138d5c75SRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
255*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((%n umin %m) umin_seq %k umin_seq %q)
256138d5c75SRoman Lebedev; CHECK-NEXT:   Predicates:
257138d5c75SRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
258138d5c75SRoman Lebedev;
259138d5c75SRoman Lebedeventry:
260138d5c75SRoman Lebedev  br label %loop
261138d5c75SRoman Lebedevloop:
262138d5c75SRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
263138d5c75SRoman Lebedev  %i.next = add i32 %i, 1
264138d5c75SRoman Lebedev  %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
265138d5c75SRoman Lebedev  %umin2 = call i32 @llvm.umin.i32(i32 %n, i32 %q)
266138d5c75SRoman Lebedev  %cond_p0 = icmp uge i32 %i, %umin
267138d5c75SRoman Lebedev  %cond_p1 = icmp uge i32 %i, %k
268138d5c75SRoman Lebedev  %cond_p2 = icmp uge i32 %i, %umin2
269138d5c75SRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
270138d5c75SRoman Lebedev  %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
271138d5c75SRoman Lebedev  br i1 %cond, label %exit, label %loop
272138d5c75SRoman Lebedevexit:
273138d5c75SRoman Lebedev  ret i32 %i
274138d5c75SRoman Lebedev}
275138d5c75SRoman Lebedev
276b2be7dcfSRoman Lebedevdefine i32 @logical_or_3ops_operand_wise_redundant_umin(i32 %n, i32 %m, i32 %k) {
277b2be7dcfSRoman Lebedev; CHECK-LABEL: 'logical_or_3ops_operand_wise_redundant_umin'
278b2be7dcfSRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops_operand_wise_redundant_umin
279b2be7dcfSRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
280*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: ((%n umin %m) umin_seq %k) LoopDispositions: { %loop: Computable }
281b2be7dcfSRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
282*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + ((%n umin %m) umin_seq %k)) LoopDispositions: { %loop: Computable }
283b2be7dcfSRoman Lebedev; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
284b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
285b2be7dcfSRoman Lebedev; CHECK-NEXT:    %umin2 = call i32 @llvm.umin.i32(i32 %n, i32 %k)
286b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> (%n umin %k) U: full-set S: full-set Exits: (%n umin %k) LoopDispositions: { %loop: Invariant }
287b2be7dcfSRoman Lebedev; CHECK-NEXT:    %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
288b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> %cond_p3 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
289b2be7dcfSRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
290b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
291b2be7dcfSRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops_operand_wise_redundant_umin
292*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is ((%n umin %m) umin_seq %k)
293b2be7dcfSRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
294*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((%n umin %m) umin_seq %k)
295b2be7dcfSRoman Lebedev; CHECK-NEXT:   Predicates:
296b2be7dcfSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
297b2be7dcfSRoman Lebedev;
298b2be7dcfSRoman Lebedeventry:
299b2be7dcfSRoman Lebedev  br label %loop
300b2be7dcfSRoman Lebedevloop:
301b2be7dcfSRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
302b2be7dcfSRoman Lebedev  %i.next = add i32 %i, 1
303b2be7dcfSRoman Lebedev  %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
304b2be7dcfSRoman Lebedev  %umin2 = call i32 @llvm.umin.i32(i32 %n, i32 %k)
305b2be7dcfSRoman Lebedev  %cond_p0 = icmp uge i32 %i, %umin
306b2be7dcfSRoman Lebedev  %cond_p1 = icmp uge i32 %i, %k
307b2be7dcfSRoman Lebedev  %cond_p2 = icmp uge i32 %i, %umin2
308b2be7dcfSRoman Lebedev  %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
309b2be7dcfSRoman Lebedev  %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
310b2be7dcfSRoman Lebedev  br i1 %cond, label %exit, label %loop
311b2be7dcfSRoman Lebedevexit:
312b2be7dcfSRoman Lebedev  ret i32 %i
313b2be7dcfSRoman Lebedev}
314b2be7dcfSRoman Lebedev
315b2be7dcfSRoman Lebedevdefine i32 @logical_or_3ops_partially_redundant_umin(i32 %n, i32 %m, i32 %k) {
316b2be7dcfSRoman Lebedev; CHECK-LABEL: 'logical_or_3ops_partially_redundant_umin'
317b2be7dcfSRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @logical_or_3ops_partially_redundant_umin
318b2be7dcfSRoman Lebedev; CHECK-NEXT:    %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
319*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%loop> U: full-set S: full-set Exits: (%n umin_seq (%m umin %k)) LoopDispositions: { %loop: Computable }
320b2be7dcfSRoman Lebedev; CHECK-NEXT:    %i.next = add i32 %i, 1
321*5ceb070bSRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%loop> U: full-set S: full-set Exits: (1 + (%n umin_seq (%m umin %k))) LoopDispositions: { %loop: Computable }
322b2be7dcfSRoman Lebedev; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
323b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
324b2be7dcfSRoman Lebedev; CHECK-NEXT:    %umin2 = call i32 @llvm.umin.i32(i32 %umin, i32 %k)
325b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> (%n umin %m umin %k) U: full-set S: full-set Exits: (%n umin %m umin %k) LoopDispositions: { %loop: Invariant }
326b2be7dcfSRoman Lebedev; CHECK-NEXT:    %cond = select i1 %cond_p0, i1 true, i1 %cond_p1
327b2be7dcfSRoman Lebedev; CHECK-NEXT:    --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
328b2be7dcfSRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @logical_or_3ops_partially_redundant_umin
329*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: backedge-taken count is (%n umin_seq (%m umin %k))
330b2be7dcfSRoman Lebedev; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
331*5ceb070bSRoman Lebedev; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is (%n umin_seq (%m umin %k))
332b2be7dcfSRoman Lebedev; CHECK-NEXT:   Predicates:
333b2be7dcfSRoman Lebedev; CHECK:       Loop %loop: Trip multiple is 1
334b2be7dcfSRoman Lebedev;
335b2be7dcfSRoman Lebedeventry:
336b2be7dcfSRoman Lebedev  br label %loop
337b2be7dcfSRoman Lebedevloop:
338b2be7dcfSRoman Lebedev  %i = phi i32 [0, %entry], [%i.next, %loop]
339b2be7dcfSRoman Lebedev  %i.next = add i32 %i, 1
340b2be7dcfSRoman Lebedev  %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
341b2be7dcfSRoman Lebedev  %umin2 = call i32 @llvm.umin.i32(i32 %umin, i32 %k)
342b2be7dcfSRoman Lebedev  %cond_p0 = icmp uge i32 %i, %n
343b2be7dcfSRoman Lebedev  %cond_p1 = icmp uge i32 %i, %umin2
344b2be7dcfSRoman Lebedev  %cond = select i1 %cond_p0, i1 true, i1 %cond_p1
345b2be7dcfSRoman Lebedev  br i1 %cond, label %exit, label %loop
346b2be7dcfSRoman Lebedevexit:
347b2be7dcfSRoman Lebedev  ret i32 %i
348b2be7dcfSRoman Lebedev}
349b2be7dcfSRoman Lebedev
350e0772cf0SRoman Lebedevdefine i32 @computeSCEVAtScope(i32 %d.0) {
351e0772cf0SRoman Lebedev; CHECK-LABEL: 'computeSCEVAtScope'
352e0772cf0SRoman Lebedev; CHECK-NEXT:  Classifying expressions for: @computeSCEVAtScope
353e0772cf0SRoman Lebedev; CHECK-NEXT:    %d.1 = phi i32 [ %inc, %for.body ], [ %d.0, %for.cond.preheader ]
3545e166507SRoman Lebedev; CHECK-NEXT:    --> {%d.0,+,1}<nsw><%for.cond> U: full-set S: full-set Exits: 0 LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
355e0772cf0SRoman Lebedev; CHECK-NEXT:    %e.1 = phi i32 [ %inc3, %for.body ], [ %d.0, %for.cond.preheader ]
3565e166507SRoman Lebedev; CHECK-NEXT:    --> {%d.0,+,1}<nsw><%for.cond> U: full-set S: full-set Exits: 0 LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
357e0772cf0SRoman Lebedev; CHECK-NEXT:    %0 = select i1 %tobool1, i1 %tobool2, i1 false
3585e166507SRoman Lebedev; CHECK-NEXT:    --> %0 U: full-set S: full-set Exits: false LoopDispositions: { %for.cond: Variant, %while.cond: Variant }
359e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc = add nsw i32 %d.1, 1
3605e166507SRoman Lebedev; CHECK-NEXT:    --> {(1 + %d.0),+,1}<nw><%for.cond> U: full-set S: full-set Exits: 1 LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
361e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc3 = add nsw i32 %e.1, 1
3625e166507SRoman Lebedev; CHECK-NEXT:    --> {(1 + %d.0),+,1}<nw><%for.cond> U: full-set S: full-set Exits: 1 LoopDispositions: { %for.cond: Computable, %while.cond: Variant }
363e0772cf0SRoman Lebedev; CHECK-NEXT:    %f.1 = phi i32 [ %inc8, %for.body5 ], [ 0, %for.cond4.preheader ]
3645e166507SRoman Lebedev; CHECK-NEXT:    --> {0,+,1}<%for.cond4> U: [0,1) S: [0,1) Exits: 0 LoopDispositions: { %for.cond4: Computable, %while.cond: Variant }
365e0772cf0SRoman Lebedev; CHECK-NEXT:    %inc8 = add i32 %f.1, 1
3665e166507SRoman Lebedev; CHECK-NEXT:    --> {1,+,1}<%for.cond4> U: [1,2) S: [1,2) Exits: 1 LoopDispositions: { %for.cond4: Computable, %while.cond: Variant }
367e0772cf0SRoman Lebedev; CHECK-NEXT:  Determining loop execution counts for: @computeSCEVAtScope
3685e166507SRoman Lebedev; CHECK-NEXT:  Loop %for.cond: backedge-taken count is (-1 * %d.0)
369e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %for.cond: max backedge-taken count is -1
3705e166507SRoman Lebedev; CHECK-NEXT:  Loop %for.cond: Predicated backedge-taken count is (-1 * %d.0)
371e0772cf0SRoman Lebedev; CHECK-NEXT:   Predicates:
372e0772cf0SRoman Lebedev; CHECK:       Loop %for.cond: Trip multiple is 1
3735e166507SRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: backedge-taken count is 0
3745e166507SRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: max backedge-taken count is 0
3755e166507SRoman Lebedev; CHECK-NEXT:  Loop %for.cond4: Predicated backedge-taken count is 0
376e0772cf0SRoman Lebedev; CHECK-NEXT:   Predicates:
377e0772cf0SRoman Lebedev; CHECK:       Loop %for.cond4: Trip multiple is 1
378e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: <multiple exits> Unpredictable backedge-taken count.
379e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: Unpredictable max backedge-taken count.
380e0772cf0SRoman Lebedev; CHECK-NEXT:  Loop %while.cond: Unpredictable predicated backedge-taken count.
381e0772cf0SRoman Lebedev;
382e0772cf0SRoman Lebedeventry:
383e0772cf0SRoman Lebedev  br label %while.cond
384e0772cf0SRoman Lebedev
385e0772cf0SRoman Lebedevwhile.cond.loopexit:                              ; preds = %for.cond4
386e0772cf0SRoman Lebedev  br label %while.cond
387e0772cf0SRoman Lebedev
388e0772cf0SRoman Lebedevwhile.cond:                                       ; preds = %while.cond.loopexit, %entry
389e0772cf0SRoman Lebedev  br label %for.cond.preheader
390e0772cf0SRoman Lebedev
391e0772cf0SRoman Lebedevfor.cond.preheader:                               ; preds = %while.cond
392e0772cf0SRoman Lebedev  br label %for.cond
393e0772cf0SRoman Lebedev
394e0772cf0SRoman Lebedevfor.cond:                                         ; preds = %for.body, %for.cond.preheader
395e0772cf0SRoman Lebedev  %d.1 = phi i32 [ %inc, %for.body ], [ %d.0, %for.cond.preheader ]
396e0772cf0SRoman Lebedev  %e.1 = phi i32 [ %inc3, %for.body ], [ %d.0, %for.cond.preheader ]
397e0772cf0SRoman Lebedev  %tobool1 = icmp ne i32 %e.1, 0
398e0772cf0SRoman Lebedev  %tobool2 = icmp ne i32 %d.1, 0
399e0772cf0SRoman Lebedev  %0 = select i1 %tobool1, i1 %tobool2, i1 false
400e0772cf0SRoman Lebedev  br i1 %0, label %for.body, label %for.cond4.preheader
401e0772cf0SRoman Lebedev
402e0772cf0SRoman Lebedevfor.cond4.preheader:                              ; preds = %for.cond
403e0772cf0SRoman Lebedev  br label %for.cond4
404e0772cf0SRoman Lebedev
405e0772cf0SRoman Lebedevfor.body:                                         ; preds = %for.cond
406e0772cf0SRoman Lebedev  %inc = add nsw i32 %d.1, 1
407e0772cf0SRoman Lebedev  %inc3 = add nsw i32 %e.1, 1
408e0772cf0SRoman Lebedev  br label %for.cond
409e0772cf0SRoman Lebedev
410e0772cf0SRoman Lebedevfor.cond4:                                        ; preds = %for.body5, %for.cond4.preheader
411e0772cf0SRoman Lebedev  %f.1 = phi i32 [ %inc8, %for.body5 ], [ 0, %for.cond4.preheader ]
412e0772cf0SRoman Lebedev  %exitcond.not = icmp eq i32 %f.1, %e.1
413e0772cf0SRoman Lebedev  br i1 %exitcond.not, label %while.cond.loopexit, label %for.body5
414e0772cf0SRoman Lebedev
415e0772cf0SRoman Lebedevfor.body5:                                        ; preds = %for.cond4
416e0772cf0SRoman Lebedev  %inc8 = add i32 %f.1, 1
417e0772cf0SRoman Lebedev  br label %for.cond4
418e0772cf0SRoman Lebedev}
419138d5c75SRoman Lebedev
420138d5c75SRoman Lebedevdeclare i32 @llvm.umin.i32(i32, i32)
421