Revert "[InstCombine] Support gep nuw in icmp folds" (#118698)
[llvm-project.git] / flang / test / Lower / HLFIR / parent-component-ref.f90
blob7d04ef3b40a65079dd003d6cfbe2575e5613ac9e
1 ! Test lowering of parent component references to HLFIR.
2 ! RUN: bbc -emit-hlfir -o - %s -I nw | FileCheck %s
4 module pc_types
5 type t
6 integer :: i
7 end type
8 type, extends(t) :: t2
9 integer :: j
10 end type
11 interface
12 subroutine takes_t_type_array(x)
13 import :: t
14 type(t) :: x(:)
15 end subroutine
16 subroutine takes_t_class_array(x)
17 import :: t
18 class(t) :: x(:)
19 end subroutine
20 subroutine takes_int_array(x)
21 integer :: x(:)
22 end subroutine
23 end interface
24 end module
26 subroutine test_inner_parent_comp(x)
27 use pc_types
28 type(t2) :: x
29 call takes_int(x%t%i)
30 end subroutine
31 ! CHECK-LABEL: func.func @_QPtest_inner_parent_comp(
32 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ex"
33 ! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"t"} : (!fir.ref<!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>) -> !fir.ref<!fir.type<_QMpc_typesTt{i:i32}>>
34 ! CHECK: %[[VAL_3:.*]] = hlfir.designate %[[VAL_2]]{"i"} : (!fir.ref<!fir.type<_QMpc_typesTt{i:i32}>>) -> !fir.ref<i32>
35 ! CHECK: fir.call @_QPtakes_int(%[[VAL_3]])
37 subroutine test_inner_parent_comp_2(x)
38 use pc_types
39 type(t2) :: x(:)
40 call takes_int_array(x%t%i)
41 end subroutine
42 ! CHECK-LABEL: func.func @_QPtest_inner_parent_comp_2(
43 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ex"
44 ! CHECK: %[[VAL_2:.*]] = arith.constant 0 : index
45 ! CHECK: %[[VAL_3:.*]]:3 = fir.box_dims %[[VAL_1]]#0, %[[VAL_2]] : (!fir.box<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, index) -> (index, index, index)
46 ! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_3]]#1 : (index) -> !fir.shape<1>
47 ! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_1]]#0{"t"} shape %[[VAL_4]] : (!fir.box<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
48 ! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_5]]{"i"} shape %[[VAL_4]] : (!fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>>
49 ! CHECK: fir.call @_QPtakes_int_array(%[[VAL_6]])
51 subroutine test_leaf_parent_ref(x)
52 use pc_types
53 type(t2) :: x
54 call takes_parent(x%t)
55 end subroutine
56 ! CHECK-LABEL: func.func @_QPtest_leaf_parent_ref(
57 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ex"
58 ! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"t"} : (!fir.ref<!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>) -> !fir.ref<!fir.type<_QMpc_typesTt{i:i32}>>
59 ! CHECK: fir.call @_QPtakes_parent(%[[VAL_2]])
61 subroutine test_leaf_parent_ref_array(x)
62 use pc_types
63 class(t2) :: x(42:)
64 ! CHECK-LABEL: func.func @_QPtest_leaf_parent_ref_array(
65 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare {{.*}}Ex"
66 call takes_t_type_array(x%t)
67 ! CHECK: %[[VAL_5:.*]] = arith.constant 0 : index
68 ! CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_5]] : (!fir.class<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, index) -> (index, index, index)
69 ! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]]#1 : (index) -> !fir.shape<1>
70 ! CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_4]]#0{"t"} shape %[[VAL_7]] : (!fir.class<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
71 ! CHECK: fir.call @_QPtakes_t_type_array(%[[VAL_8]])
72 call takes_t_class_array(x%t)
73 ! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_4]]#0{"t"} shape %{{.*}} : (!fir.class<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
74 ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_12]] : (!fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>) -> !fir.class<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
75 ! CHECK: fir.call @_QPtakes_t_class_array(%[[VAL_13]])
76 end subroutine
78 subroutine test_parent_section_leaf_array(x)
79 use pc_types
80 class(t2) :: x(:)
81 call takes_t_type_array(x(2:11)%t)
82 end subroutine
83 ! CHECK-LABEL: func.func @_QPtest_parent_section_leaf_array(
84 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ex"
85 ! CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_1]]#0 ({{.*}}) shape %[[VAL_6:.*]] : (!fir.class<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, index, index, index, !fir.shape<1>) -> !fir.class<!fir.array<10x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>
86 ! CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_7]]{"t"} shape %[[VAL_6]] : (!fir.class<!fir.array<10x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<10x!fir.type<_QMpc_typesTt{i:i32}>>>
87 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.array<10x!fir.type<_QMpc_typesTt{i:i32}>>>) -> !fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
88 ! CHECK: fir.call @_QPtakes_t_type_array(%[[VAL_9]])
90 subroutine test_pointer_leaf_parent_ref_array(x)
91 use pc_types
92 class(t2), pointer :: x(:)
93 call takes_t_type_array(x%t)
94 end subroutine
95 ! CHECK-LABEL: func.func @_QPtest_pointer_leaf_parent_ref_array(
96 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ex"
97 ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>>>
98 ! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
99 ! CHECK: %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_2]], %[[VAL_3]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>>, index) -> (index, index, index)
100 ! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]]#1 : (index) -> !fir.shape<1>
101 ! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_2]]{"t"} shape %[[VAL_5]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpc_typesTt2{t:!fir.type<_QMpc_typesTt{i:i32}>,j:i32}>>>>, !fir.shape<1>) -> !fir.box<!fir.array<?x!fir.type<_QMpc_typesTt{i:i32}>>>
102 ! CHECK: fir.call @_QPtakes_t_type_array(%[[VAL_6]])