[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / mixed_loops.f90
blob651919dd5b3b1cad245cef6aefe2e4826e29d31a
1 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
2 ! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s
4 ! Test while loop inside do loop.
5 ! CHECK-LABEL: while_inside_do_loop
6 subroutine while_inside_do_loop
7 ! CHECK-DAG: %[[T_REF:.*]] = fir.alloca i32
8 ! CHECK-DAG: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFwhile_inside_do_loopEi"}
9 ! CHECK-DAG: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFwhile_inside_do_loopEj"}
10 integer :: i, j
12 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : i32
13 ! CHECK-DAG: %[[C8:.*]] = arith.constant 8 : i32
14 ! CHECK-DAG: %[[C13:.*]] = arith.constant 13 : i32
15 ! CHECK: %[[DIFF:.*]] = arith.subi %[[C13]], %[[C8]] : i32
16 ! CHECK: %[[RANGE:.*]] = arith.addi %[[DIFF]], %[[C1]] : i32
17 ! CHECK: %[[HIGH:.*]] = arith.divsi %[[RANGE]], %[[C1]] : i32
18 ! CHECK: fir.store %[[HIGH]] to %[[T_REF]] : !fir.ref<i32>
19 ! CHECK: fir.store %[[C8]] to %[[I_REF]] : !fir.ref<i32>
21 ! CHECK: br ^[[HDR1:.*]]
22 ! CHECK: ^[[HDR1]]: // 2 preds: ^{{.*}}, ^[[EXIT2:.*]]
23 ! CHECK-DAG: %[[T:.*]] = fir.load %[[T_REF]] : !fir.ref<i32>
24 ! CHECK-DAG: %[[C0:.*]] = arith.constant 0 : i32
25 ! CHECK: %[[COND:.*]] = arith.cmpi sgt, %[[T]], %[[C0]] : i32
26 ! CHECK: cond_br %[[COND]], ^[[BODY1:.*]], ^[[EXIT1:.*]]
27 do i=8,13
28 ! CHECK: ^[[BODY1]]: // pred: ^[[HDR1]]
29 ! CHECK: %[[C3:.*]] = arith.constant 3 : i32
30 ! CHECK: fir.store %[[C3]] to %[[J_REF]] : !fir.ref<i32>
31 j=3
33 ! CHECK: br ^[[HDR2:.*]]
34 ! CHECK: ^[[HDR2]]: // 2 preds: ^[[BODY1]], ^[[BODY2:.*]]
35 ! CHECK-DAG: %[[J:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
36 ! CHECK-DAG: %[[I:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
37 ! CHECK: %[[COND2:.*]] = arith.cmpi slt, %[[J]], %[[I]] : i32
38 ! CHECK: cond_br %[[COND2]], ^[[BODY2]], ^[[EXIT2]]
39 do while (j .lt. i)
40 ! CHECK: ^[[BODY2]]: // pred: ^[[HDR2]]
41 ! CHECK-DAG: %[[J2:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
42 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
43 ! CHECK: %[[INC2:.*]] = arith.muli %[[C2]], %[[J2]] : i32
44 ! CHECK: fir.store %[[INC2]] to %[[J_REF]] : !fir.ref<i32>
45 j=j*2
46 ! CHECK: br ^[[HDR2]]
47 end do
49 ! CHECK: ^[[EXIT2]]: // pred: ^[[HDR2]]
50 ! CHECK-DAG: %[[T2:.*]] = fir.load %[[T_REF]] : !fir.ref<i32>
51 ! CHECK-DAG: %[[C1_AGAIN:.*]] = arith.constant 1 : i32
52 ! CHECK: %[[TDEC:.*]] = arith.subi %[[T2]], %[[C1_AGAIN]] : i32
53 ! CHECK: fir.store %[[TDEC]] to %[[T_REF]]
54 ! CHECK: %[[I3:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
55 ! CHECK: %[[IINC:.*]] = arith.addi %[[I3]], %[[C1]] : i32
56 ! CHECK: fir.store %[[IINC]] to %[[I_REF]] : !fir.ref<i32>
57 ! CHECK: br ^[[HDR1]]
58 end do
60 ! CHECK: ^[[EXIT1]]: // pred: ^[[HDR1]]
61 ! CHECK: %[[IPRINT:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
62 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[IPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
63 ! CHECK: %[[JPRINT:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
64 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[JPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
65 print *, i, j
66 end subroutine
68 ! Test do loop inside while loop.
69 ! CHECK-LABEL: do_inside_while_loop
70 subroutine do_inside_while_loop
71 ! CHECK-DAG: %[[I_REF:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFdo_inside_while_loopEi"}
72 ! CHECK-DAG: %[[J_REF:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFdo_inside_while_loopEj"}
73 integer :: i, j
75 ! CHECK: %[[C3:.*]] = arith.constant 3 : i32
76 ! CHECK: fir.store %[[C3]] to %[[J_REF]] : !fir.ref<i32>
77 j=3
79 ! CHECK: br ^[[HDR1:.*]]
80 ! CHECK: ^[[HDR1]]: // 2 preds: ^{{.*}}, ^[[BODY1:.*]]
81 ! CHECK-DAG: %[[J:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
82 ! CHECK-DAG: %[[UL:.*]] = arith.constant 21 : i32
83 ! CHECK: %[[COND:.*]] = arith.cmpi slt, %[[J]], %[[UL]] : i32
84 ! CHECK: cond_br %[[COND]], ^[[BODY1]], ^[[EXIT1:.*]]
85 do while (j .lt. 21)
86 ! CHECK: ^[[BODY1]]: // pred: ^[[HDR1]]
88 ! CHECK-DAG: %[[C8_I32:.*]] = arith.constant 8 : i32
89 ! CHECK-DAG: %[[C8:.*]] = fir.convert %[[C8_I32]] : (i32) -> index
90 ! CHECK-DAG: %[[C13_I32:.*]] = arith.constant 13 : i32
91 ! CHECK-DAG: %[[C13:.*]] = fir.convert %[[C13_I32]] : (i32) -> index
92 ! CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index
93 ! CHECK: %[[I_LB:.*]] = fir.convert %[[C8]] : (index) -> i32
94 ! CHECK: %[[RESULT:.*]]:2 = fir.do_loop %[[IDX:[^ ]*]] =
95 ! CHECK-SAME: %[[C8]] to %[[C13]] step %[[C1]]
96 ! CHECK-SAME: iter_args(%[[I_IV:.*]] = %[[I_LB]]) -> (index, i32) {
97 ! CHECK: fir.store %[[I_IV]] to %[[I_REF]] : !fir.ref<i32>
98 ! CHECK-DAG: %[[J2:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
99 ! CHECK-DAG: %[[C2:.*]] = arith.constant 2 : i32
100 ! CHECK: %[[JINC:.*]] = arith.muli %[[C2]], %[[J2]] : i32
101 ! CHECK: fir.store %[[JINC]] to %[[J_REF]] : !fir.ref<i32>
102 ! CHECK: %[[IINC:.*]] = arith.addi %[[IDX]], %[[C1]] : index
103 ! CHECK: %[[I_STEPCAST:.*]] = fir.convert %[[C1]] : (index) -> i32
104 ! CHECK: %[[I_IVLOAD:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
105 ! CHECK: %[[I_IVINC:.*]] = arith.addi %[[I_IVLOAD]], %[[I_STEPCAST]] : i32
106 ! CHECK: fir.result %[[IINC]], %[[I_IVINC]] : index, i32
107 do i=8,13
108 j=j*2
110 ! CHECK: fir.store %[[RESULT]]#1 to %[[I_REF]] : !fir.ref<i32>
111 end do
113 ! CHECK: br ^[[HDR1]]
114 end do
116 ! CHECK: ^[[EXIT1]]: // pred: ^[[HDR1]]
117 ! CHECK: %[[IPRINT:.*]] = fir.load %[[I_REF]] : !fir.ref<i32>
118 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[IPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
119 ! CHECK: %[[JPRINT:.*]] = fir.load %[[J_REF]] : !fir.ref<i32>
120 ! CHECK: fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[JPRINT]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
121 print *, i, j
122 end subroutine