1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s
4 ! Tests for infinite loop.
6 subroutine empty_infinite()
10 ! CHECK-LABEL: empty_infinite
11 ! CHECK: cf.br ^[[BODY:.*]]
13 ! CHECK: cf.br ^[[BODY]]
15 subroutine simple_infinite(i
)
21 ! CHECK-LABEL: simple_infinite
22 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
23 ! CHECK: cf.br ^[[BODY1:.*]]
25 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
26 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
27 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
28 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY1:.*]]
30 ! CHECK: cf.br ^[[RETURN:.*]]
35 subroutine infinite_with_two_body_blocks(i
)
43 ! CHECK-LABEL: infinite_with_two_body_blocks
44 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
45 ! CHECK: cf.br ^[[BODY1:.*]]
47 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
48 ! CHECK: %[[C1:.*]] = arith.constant 1 : i32
49 ! CHECK: %[[I_NEXT:.*]] = arith.addi %[[I]], %[[C1]] : i32
50 ! CHECK: fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
51 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
52 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
53 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
54 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
56 ! CHECK: cf.br ^[[RETURN:.*]]
58 ! CHECK: %[[C2:.*]] = arith.constant 2 : i32
59 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
60 ! CHECK: %[[I_NEXT:.*]] = arith.muli %[[C2]], %[[I]] : i32
61 ! CHECK: fir.store %[[I_NEXT]] to %[[I_REF]] : !fir.ref<i32>
62 ! CHECK: cf.br ^[[BODY1]]
67 subroutine structured_loop_in_infinite(i
)
76 ! CHECK-LABEL: structured_loop_in_infinite
77 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
78 ! CHECK: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFstructured_loop_in_infiniteEj"}
79 ! CHECK: cf.br ^[[BODY1:.*]]
81 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
82 ! CHECK: %[[C100:.*]] = arith.constant 100 : i32
83 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C100]] : i32
84 ! CHECK: cf.cond_br %[[COND]], ^[[EXIT:.*]], ^[[BODY2:.*]]
86 ! CHECK: cf.br ^[[RETURN:.*]]
87 ! CHECK: ^[[BODY2:.*]]:
88 ! CHECK: %[[C1:.*]] = arith.constant 1 : i32
89 ! CHECK: %[[C1_INDEX:.*]] = fir.convert %[[C1]] : (i32) -> index
90 ! CHECK: %[[C10:.*]] = arith.constant 10 : i32
91 ! CHECK: %[[C10_INDEX:.*]] = fir.convert %[[C10]] : (i32) -> index
92 ! CHECK: %[[C1_1:.*]] = arith.constant 1 : index
93 ! CHECK: %[[J_LB:.*]] = fir.convert %[[C1_INDEX]] : (index) -> i32
94 ! CHECK: %[[J_FINAL:.*]]:2 = fir.do_loop %[[J:[^ ]*]] =
95 ! CHECK-SAME: %[[C1_INDEX]] to %[[C10_INDEX]] step %[[C1_1]]
96 ! CHECK-SAME: iter_args(%[[J_IV:.*]] = %[[J_LB]]) -> (index, i32) {
97 ! CHECK: fir.store %[[J_IV]] to %[[J_REF]] : !fir.ref<i32>
98 ! CHECK: %[[J_NEXT:.*]] = arith.addi %[[J]], %[[C1_1]] : index
99 ! CHECK: %[[J_STEPCAST:.*]] = fir.convert %[[C1_1]] : (index) -> i32
100 ! CHECK: %[[J_IVLOAD:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
101 ! CHECK: %[[J_IVINC:.*]] = arith.addi %[[J_IVLOAD]], %[[J_STEPCAST]] : i32
102 ! CHECK: fir.result %[[J_NEXT]], %[[J_IVINC]] : index, i32
104 ! CHECK: fir.store %[[J_FINAL]]#1 to %[[J_REF]] : !fir.ref<i32>
105 ! CHECK: cf.br ^[[BODY1]]
106 ! CHECK: ^[[RETURN]]:
109 subroutine empty_infinite_in_while(i
)
117 ! CHECK-LABEL: empty_infinite_in_while
118 ! CHECK-SAME: %[[I_REF:.*]]: !fir.ref<i32>
121 ! CHECK: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
122 ! CHECK: %[[C50:.*]] = arith.constant 50 : i32
123 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C50]] : i32
124 ! CHECK: cf.cond_br %[[COND]], ^[[INF_HEADER:.*]], ^[[EXIT:.*]]
125 ! CHECK: ^[[INF_HEADER]]:
126 ! CHECK: cf.br ^[[INF_BODY:.*]]
127 ! CHECK: ^[[INF_BODY]]:
128 ! CHECK: cf.br ^[[INF_HEADER]]