[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / loops2.f90
blob78795fa642ea42e4902a2118487ce2587269c6ab
1 ! Test loop variables increment
2 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
4 module test_loop_var
5 implicit none
6 integer, pointer:: i_pointer
7 integer, allocatable :: i_allocatable
8 real, pointer :: x_pointer
9 real, allocatable :: x_allocatable
10 contains
11 ! CHECK-LABEL: func @_QMtest_loop_varPtest_pointer
12 subroutine test_pointer()
13 do i_pointer=1,10
14 enddo
15 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QMtest_loop_varEi_pointer) : !fir.ref<!fir.box<!fir.ptr<i32>>>
16 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
17 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
18 ! CHECK: %[[VAL_9:.*]]:2 = fir.do_loop{{.*}}iter_args(%[[IV:.*]] = {{.*}})
19 ! CHECK: fir.store %[[IV]] to %[[VAL_2]] : !fir.ptr<i32>
20 ! CHECK: }
21 ! CHECK: fir.store %[[VAL_9]]#1 to %[[VAL_2]] : !fir.ptr<i32>
22 end subroutine
24 ! CHECK-LABEL: func @_QMtest_loop_varPtest_allocatable
25 subroutine test_allocatable()
26 do i_allocatable=1,10
27 enddo
28 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QMtest_loop_varEi_allocatable) : !fir.ref<!fir.box<!fir.heap<i32>>>
29 ! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<i32>>>
30 ! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32>
31 ! CHECK: %[[VAL_9:.*]]:2 = fir.do_loop{{.*}}iter_args(%[[IV:.*]] = {{.*}})
32 ! CHECK: fir.store %[[IV]] to %[[VAL_2]] : !fir.heap<i32>
33 ! CHECK: }
34 ! CHECK: fir.store %[[VAL_9]]#1 to %[[VAL_2]] : !fir.heap<i32>
35 end subroutine
37 ! CHECK-LABEL: func @_QMtest_loop_varPtest_real_pointer
38 subroutine test_real_pointer()
39 do x_pointer=1,10
40 enddo
41 ! CHECK: %[[VAL_0:.*]] = fir.alloca index
42 ! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEx_pointer) : !fir.ref<!fir.box<!fir.ptr<f32>>>
43 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<f32>>>
44 ! CHECK: %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
45 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
46 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> f32
47 ! CHECK: %[[VAL_8:.*]] = arith.constant 1.000000e+00 : f32
49 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_3]] : !fir.ptr<f32>
50 ! CHECK: br ^bb1
51 ! CHECK: ^bb1:
52 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb3
53 ! CHECK: ^bb2:
54 ! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_3]] : !fir.ptr<f32>
55 ! CHECK: %[[VAL_20:.*]] = arith.addf %[[VAL_19]], %[[VAL_8]] {{.*}}: f32
56 ! CHECK: fir.store %[[VAL_20]] to %[[VAL_3]] : !fir.ptr<f32>
57 ! CHECK: br ^bb1
58 ! CHECK: ^bb3:
59 ! CHECK: return
60 end subroutine
62 ! CHECK-LABEL: func @_QMtest_loop_varPtest_real_allocatable
63 subroutine test_real_allocatable()
64 do x_allocatable=1,10
65 enddo
66 ! CHECK: %[[VAL_0:.*]] = fir.alloca index
67 ! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEx_allocatable) : !fir.ref<!fir.box<!fir.heap<f32>>>
68 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<f32>>>
69 ! CHECK: %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>
70 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
71 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> f32
72 ! CHECK: %[[VAL_8:.*]] = arith.constant 1.000000e+00 : f32
74 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_3]] : !fir.heap<f32>
75 ! CHECK: br ^bb1
76 ! CHECK: ^bb1:
77 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb3
78 ! CHECK: ^bb2:
79 ! CHECK: %[[VAL_19:.*]] = fir.load %[[VAL_3]] : !fir.heap<f32>
80 ! CHECK: %[[VAL_20:.*]] = arith.addf %[[VAL_19]], %[[VAL_8]] {{.*}}: f32
81 ! CHECK: fir.store %[[VAL_20]] to %[[VAL_3]] : !fir.heap<f32>
82 ! CHECK: br ^bb1
83 ! CHECK: ^bb3:
84 ! CHECK: return
85 end subroutine
87 ! CHECK-LABEL: func @_QMtest_loop_varPtest_pointer_unstructured_loop()
88 subroutine test_pointer_unstructured_loop()
89 do i_pointer=1,10
90 if (i_pointer .gt. 5) exit
91 enddo
92 ! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEi_pointer) : !fir.ref<!fir.box<!fir.ptr<i32>>>
93 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
94 ! CHECK: %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
95 ! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
96 ! CHECK: %[[VAL_6:.*]] = arith.constant 1 : i32
97 ! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ptr<i32>
98 ! CHECK: br ^bb1
99 ! CHECK: ^bb1:
100 ! CHECK: cond_br %{{.*}}, ^bb2, ^bb5
101 ! CHECK: ^bb2:
102 ! CHECK: cond_br %{{.*}}, ^bb3, ^bb4
103 ! CHECK: ^bb3:
104 ! CHECK: br ^bb5
105 ! CHECK: ^bb4:
106 ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_3]] : !fir.ptr<i32>
107 ! CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_21]], %[[VAL_6]] : i32
108 ! CHECK: fir.store %[[VAL_22]] to %[[VAL_3]] : !fir.ptr<i32>
109 ! CHECK: br ^bb1
110 ! CHECK: ^bb5:
111 ! CHECK: return
112 ! CHECK: }
113 end subroutine
115 end module
117 use test_loop_var
118 implicit none
119 integer, target :: i_target = -1
120 real, target :: x_target = -1.
121 i_pointer => i_target
122 allocate(i_allocatable)
123 i_allocatable = -1
124 x_pointer => x_target
125 allocate(x_allocatable)
126 x_allocatable = -1.
128 call test_pointer()
129 call test_allocatable()
130 call test_real_pointer()
131 call test_real_allocatable()
132 ! Expect 11 everywhere
133 print *, i_target
134 print *, i_allocatable
135 print *, x_target
136 print *, x_allocatable
138 call test_pointer_unstructured_loop()
139 call test_allocatable_unstructured_loop()
140 ! Expect 6 everywhere
141 print *, i_target