[ARM] Stop gluing ALU nodes to branches / selects (#116970)
[llvm-project.git] / flang / test / Lower / while_loop.f90
blob8c03ff5ba9b189a7011814856a8a538aa4d69a8c
1 ! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -o - %s | FileCheck %s
4 ! Test a simple while loop.
5 ! CHECK-LABEL: simple_loop
6 subroutine simple_loop
7 ! CHECK: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_loopEi"}
8 integer :: i
10 ! CHECK: %[[C5:.*]] = arith.constant 5 : i32
11 ! CHECK: fir.store %[[C5]] to %[[I_REF]]
12 i = 5
14 ! CHECK: br ^[[BB1:.*]]
15 ! CHECK: ^[[BB1]]: // 2 preds: ^{{.*}}, ^[[BB2:.*]]
16 ! CHECK-DAG: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
17 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : i32
18 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C1]] : i32
19 ! CHECK: cond_br %[[COND]], ^[[BB2]], ^[[BB3:.*]]
20 ! CHECK: ^[[BB2]]: // pred: ^[[BB1]]
21 ! CHECK-DAG: %[[I2:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
22 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
23 ! CHECK: %[[INC:.*]] = arith.subi %[[I2]], %[[C2]] : i32
24 ! CHECK: fir.store %[[INC]] to %[[I_REF]] : !fir.ref<i32>
25 ! CHECK: br ^[[BB1]]
26 do while (i .gt. 1)
27 i = i - 2
28 end do
30 ! CHECK: ^[[BB3]]: // pred: ^[[BB1]]
31 ! CHECK: %[[I3:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
32 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[I3]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
33 print *, i
34 end subroutine
36 ! Test 2 nested while loops.
37 ! CHECK-LABEL: while_inside_while_loop
38 subroutine while_inside_while_loop
39 ! CHECK-DAG: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFwhile_inside_while_loopEi"}
40 ! CHECK-DAG: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFwhile_inside_while_loopEj"}
41 integer :: i, j
43 ! CHECK: %[[C13:.*]] = arith.constant 13 : i32
44 ! CHECK: fir.store %[[C13]] to %[[I_REF]]
45 i = 13
47 ! CHECK: br ^[[HDR1:.*]]
48 ! CHECK: ^[[HDR1]]: // 2 preds: ^{{.*}}, ^[[EXIT2:.*]]
49 ! CHECK-DAG: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
50 ! CHECK-DAG: %[[C8:.*]] = arith.constant 8 : i32
51 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[I]], %[[C8]] : i32
52 ! CHECK: cond_br %[[COND]], ^[[BODY1:.*]], ^[[EXIT1:.*]]
53 do while (i .gt. 8)
54 ! CHECK: ^[[BODY1]]: // pred: ^[[HDR1]]
55 ! CHECK-DAG: %[[I2:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
56 ! CHECK-DAG: %[[C5:.*]] = arith.constant 5 : i32
57 ! CHECK: %[[INC:.*]] = arith.subi %[[I2]], %[[C5]] : i32
58 ! CHECK: fir.store %[[INC]] to %[[I_REF]] : !fir.ref<i32>
59 i = i - 5
61 ! CHECK: %[[C3:.*]] = arith.constant 3 : i32
62 ! CHECK: fir.store %[[C3]] to %[[J_REF]]
63 j = 3
65 ! CHECK: br ^[[HDR2:.*]]
66 ! CHECK: ^[[HDR2]]: // 2 preds: ^[[BODY1]], ^[[BODY2:.*]]
67 ! CHECK-DAG: %[[J:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
68 ! CHECK-DAG: %[[I3:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
69 ! CHECK: %[[COND2:.*]] = arith.cmpi slt, %[[J]], %[[I3]] : i32
70 ! CHECK: cond_br %[[COND2]], ^[[BODY2]], ^[[EXIT2]]
71 do while (j .lt. i)
72 ! CHECK: ^[[BODY2]]: // pred: ^[[HDR2]]
73 ! CHECK-DAG: %[[J2:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
74 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
75 ! CHECK: %[[INC2:.*]] = arith.muli %[[C2]], %[[J2]] : i32
76 ! CHECK: fir.store %[[INC2]] to %[[J_REF]] : !fir.ref<i32>
77 j = j * 2
78 ! CHECK: br ^[[HDR2]]
79 end do
81 ! CHECK: ^[[EXIT2]]: // pred: ^[[HDR2]]
82 ! CHECK: br ^[[HDR1]]
83 end do
85 ! CHECK: ^[[EXIT1]]: // pred: ^[[HDR1]]
86 ! CHECK: %[[IPRINT:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
87 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[IPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
88 ! CHECK: %[[JPRINT:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
89 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[JPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
90 print *, i, j
91 end subroutine