Debian Codegraph @

flang/test/Transforms/tbaa4.fir

raw
1 // Test TBAA tags for common and equivalence.
2 // RUN: fir-opt --fir-add-alias-tags --split-input-file %s | FileCheck --check-prefixes=ALL,DEFAULT %s
3 // RUN: fir-opt --fir-add-alias-tags --local-alloc-tbaa --split-input-file %s | FileCheck --check-prefixes=ALL,LOCAL %s
4
5 // ALL: #[[ROOT:.+]] = #llvm.tbaa_root<id = "Flang function root _QPtest_common">
6 // ALL: #[[ANY:.+]] = #llvm.tbaa_type_desc<id = "any access", members = {<#[[ROOT]], 0>}>
7 // ALL: #[[ANYDATA:.+]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY]], 0>}>
8 // ALL: #[[TARGETDATA:.+]] = #llvm.tbaa_type_desc<id = "target data", members = {<#[[ANYDATA]], 0>}>
9 // ALL: #[[GLOBALDATA:.+]] = #llvm.tbaa_type_desc<id = "global data", members = {<#[[TARGETDATA]], 0>}>
10 // ALL: #[[BLK:.+]] = #llvm.tbaa_type_desc<id = "global data/blk_", members = {<#[[GLOBALDATA]], 0>}>
11 // ALL: #[[TAG:.+]] = #llvm.tbaa_tag<base_type = #[[BLK]], access_type = #[[BLK]], offset = 0>
12
13 module {
14 // ALL-LABEL: fir.global common @blk_(dense<0> : vector<48xi8>) {alignment = 4 : i64} : !fir.array<48xi8>
15 fir.global common @blk_(dense<0> : vector<48xi8>) {alignment = 4 : i64} : !fir.array<48xi8>
16
17 // ALL-LABEL: func.func @_QPtest_common() {
18 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<f32>
19 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<i32>
20 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<f32>
21 func.func @_QPtest_common() {
22 %c1 = arith.constant 1 : index
23 %c1_i32 = arith.constant 1 : i32
24 %cst = arith.constant 1.000000e+00 : f32
25 %c10 = arith.constant 10 : index
26 %c8 = arith.constant 8 : index
27 %c4 = arith.constant 4 : index
28 %c0 = arith.constant 0 : index
29 %0 = fir.dummy_scope : !fir.dscope
30 %1 = fir.address_of(@blk_) : !fir.ref<!fir.array<48xi8>>
31 %2 = fir.convert %1 : (!fir.ref<!fir.array<48xi8>>) -> !fir.ref<!fir.array<?xi8>>
32 %3 = fir.coordinate_of %2, %c0 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
33 %4 = fir.convert %3 : (!fir.ref<i8>) -> !fir.ref<f32>
34 %5 = fir.declare %4 {uniq_name = "_QFtest_commonEa"} : (!fir.ref<f32>) -> !fir.ref<f32>
35 %6 = fir.coordinate_of %2, %c4 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
36 %7 = fir.convert %6 : (!fir.ref<i8>) -> !fir.ref<f32>
37 %8 = fir.declare %7 {uniq_name = "_QFtest_commonEb"} : (!fir.ref<f32>) -> !fir.ref<f32>
38 %9 = fir.coordinate_of %2, %c8 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
39 %10 = fir.convert %9 : (!fir.ref<i8>) -> !fir.ref<!fir.array<10xi32>>
40 %11 = fir.shape %c10 : (index) -> !fir.shape<1>
41 %12 = fir.declare %10(%11) {uniq_name = "_QFtest_commonEc"} : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.ref<!fir.array<10xi32>>
42 fir.store %cst to %5 : !fir.ref<f32>
43 %13 = fir.array_coor %12(%11) %c1 : (!fir.ref<!fir.array<10xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
44 fir.store %c1_i32 to %13 : !fir.ref<i32>
45 fir.store %cst to %8 : !fir.ref<f32>
46 return
47 }
48 }
49
50 // -----
51
52 // LOCAL: #[[ROOT:.+]] = #llvm.tbaa_root<id = "Flang function root _QPtest_local_equiv">
53 // LOCAL: #[[ANY:.+]] = #llvm.tbaa_type_desc<id = "any access", members = {<#[[ROOT]], 0>}>
54 // LOCAL: #[[ANYDATA:.+]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY]], 0>}>
55 // LOCAL: #[[TARGETDATA:.+]] = #llvm.tbaa_type_desc<id = "target data", members = {<#[[ANYDATA]], 0>}>
56 // LOCAL: #[[ALLOCATEDDATA:.+]] = #llvm.tbaa_type_desc<id = "allocated data", members = {<#[[TARGETDATA]], 0>}>
57 // LOCAL: #[[EQUIV:.+]] = #llvm.tbaa_type_desc<id = "allocated data/_QFtest_local_equivEa", members = {<#[[ALLOCATEDDATA]], 0>}>
58 // LOCAL: #[[$ATTR_13:.+]] = #llvm.tbaa_tag<base_type = #[[EQUIV]], access_type = #[[EQUIV]], offset = 0>
59
60 // ALL-LABEL: func.func @_QPtest_local_equiv() {
61 // LOCAL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
62 // LOCAL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<i32>
63 // LOCAL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
64 // DEFAULT-NOT: fir.store{{.}}tbaa
65 func.func @_QPtest_local_equiv() {
66 %c1 = arith.constant 1 : index
67 %c1_i32 = arith.constant 1 : i32
68 %cst = arith.constant 1.000000e+00 : f32
69 %c10 = arith.constant 10 : index
70 %c0 = arith.constant 0 : index
71 %c8 = arith.constant 8 : index
72 %0 = fir.dummy_scope : !fir.dscope
73 %1 = fir.alloca !fir.array<40xi8> {uniq_name = "_QFtest_local_equivEa"}
74 %2 = fir.coordinate_of %1, %c8 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
75 %3 = fir.convert %2 : (!fir.ref<i8>) -> !fir.ptr<f32>
76 %4 = fir.declare %3 {uniq_name = "_QFtest_local_equivEa"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
77 %5 = fir.declare %3 {uniq_name = "_QFtest_local_equivEb"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
78 %6 = fir.coordinate_of %1, %c0 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
79 %7 = fir.convert %6 : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xi32>>
80 %8 = fir.shape %c10 : (index) -> !fir.shape<1>
81 %9 = fir.declare %7(%8) {uniq_name = "_QFtest_local_equivEc"} : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.ptr<!fir.array<10xi32>>
82 fir.store %cst to %4 : !fir.ptr<f32>
83 %10 = fir.array_coor %9(%8) %c1 : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
84 fir.store %c1_i32 to %10 : !fir.ref<i32>
85 fir.store %cst to %5 : !fir.ptr<f32>
86 return
87 }
88
89 // -----
90
91 // ALL: #[[ROOT:.+]] = #llvm.tbaa_root<id = "Flang function root _QPtest_save_equiv">
92 // ALL: #[[ANY:.+]] = #llvm.tbaa_type_desc<id = "any access", members = {<#[[ROOT]], 0>}>
93 // ALL: #[[ANYDATA:.+]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY]], 0>}>
94 // ALL: #[[TARGETDATA:.+]] = #llvm.tbaa_type_desc<id = "target data", members = {<#[[ANYDATA]], 0>}>
95 // ALL: #[[GLOBALDATA:.+]] = #llvm.tbaa_type_desc<id = "global data", members = {<#[[TARGETDATA]], 0>}>
96 // ALL: #[[EQUIV:.+]] = #llvm.tbaa_type_desc<id = "global data/_QFtest_save_equivEa", members = {<#[[GLOBALDATA]], 0>}>
97 // ALL: #[[TAG:.+]] = #llvm.tbaa_tag<base_type = #[[EQUIV]], access_type = #[[EQUIV]], offset = 0>
98 module {
99 // ALL-LABEL: fir.global internal @_QFtest_save_equivEa : !fir.array<40xi8> {
100 fir.global internal @_QFtest_save_equivEa : !fir.array<40xi8> {
101 %0 = fir.zero_bits !fir.array<40xi8>
102 fir.has_value %0 : !fir.array<40xi8>
103 }
104
105 // ALL-LABEL: func.func @_QPtest_save_equiv() {
106 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
107 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<i32>
108 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
109 func.func @_QPtest_save_equiv() {
110 %c1 = arith.constant 1 : index
111 %c1_i32 = arith.constant 1 : i32
112 %cst = arith.constant 1.000000e+00 : f32
113 %c10 = arith.constant 10 : index
114 %c0 = arith.constant 0 : index
115 %c8 = arith.constant 8 : index
116 %0 = fir.dummy_scope : !fir.dscope
117 %1 = fir.address_of(@_QFtest_save_equivEa) : !fir.ref<!fir.array<40xi8>>
118 %2 = fir.coordinate_of %1, %c8 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
119 %3 = fir.convert %2 : (!fir.ref<i8>) -> !fir.ptr<f32>
120 %4 = fir.declare %3 {uniq_name = "_QFtest_save_equivEa"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
121 %5 = fir.declare %3 {uniq_name = "_QFtest_save_equivEb"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
122 %6 = fir.coordinate_of %1, %c0 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
123 %7 = fir.convert %6 : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xi32>>
124 %8 = fir.shape %c10 : (index) -> !fir.shape<1>
125 %9 = fir.declare %7(%8) {uniq_name = "_QFtest_save_equivEc"} : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.ptr<!fir.array<10xi32>>
126 fir.store %cst to %4 : !fir.ptr<f32>
127 %10 = fir.array_coor %9(%8) %c1 : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
128 fir.store %c1_i32 to %10 : !fir.ref<i32>
129 fir.store %cst to %5 : !fir.ptr<f32>
130 return
131 }
132 }
133
134 // -----
135
136 // ALL: #[[ROOT:.+]] = #llvm.tbaa_root<id = "Flang function root _QPtest_global_equiv">
137 // ALL: #[[ANY:.+]] = #llvm.tbaa_type_desc<id = "any access", members = {<#[[ROOT]], 0>}>
138 // ALL: #[[ANYDATA:.+]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY]], 0>}>
139 // ALL: #[[TARGETDATA:.+]] = #llvm.tbaa_type_desc<id = "target data", members = {<#[[ANYDATA]], 0>}>
140 // ALL: #[[GLOBALDATA:.+]] = #llvm.tbaa_type_desc<id = "global data", members = {<#[[TARGETDATA]], 0>}>
141 // ALL: #[[EQUIV:.+]] = #llvm.tbaa_type_desc<id = "global data/_QMdataEa", members = {<#[[GLOBALDATA]], 0>}>
142 // ALL: #[[TAG:.+]] = #llvm.tbaa_tag<base_type = #[[EQUIV]], access_type = #[[EQUIV]], offset = 0>
143
144 module {
145 // ALL-LABEL: fir.global @_QMdataEa : !fir.array<40xi8> {
146 fir.global @_QMdataEa : !fir.array<40xi8> {
147 %0 = fir.zero_bits !fir.array<40xi8>
148 fir.has_value %0 : !fir.array<40xi8>
149 }
150 // ALL-LABEL: func.func @_QPtest_global_equiv() {
151 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
152 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ref<i32>
153 // ALL: fir.store{{.*}}{tbaa = [#[[TAG]]]} : !fir.ptr<f32>
154 func.func @_QPtest_global_equiv() {
155 %c1 = arith.constant 1 : index
156 %c1_i32 = arith.constant 1 : i32
157 %cst = arith.constant 1.000000e+00 : f32
158 %c10 = arith.constant 10 : index
159 %c0 = arith.constant 0 : index
160 %c8 = arith.constant 8 : index
161 %0 = fir.dummy_scope : !fir.dscope
162 %1 = fir.address_of(@_QMdataEa) : !fir.ref<!fir.array<40xi8>>
163 %2 = fir.coordinate_of %1, %c8 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
164 %3 = fir.convert %2 : (!fir.ref<i8>) -> !fir.ptr<f32>
165 %4 = fir.declare %3 {uniq_name = "_QMdataEa"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
166 %5 = fir.declare %3 {uniq_name = "_QMdataEb"} : (!fir.ptr<f32>) -> !fir.ptr<f32>
167 %6 = fir.coordinate_of %1, %c0 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
168 %7 = fir.convert %6 : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xi32>>
169 %8 = fir.shape %c10 : (index) -> !fir.shape<1>
170 %9 = fir.declare %7(%8) {uniq_name = "_QMdataEc"} : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>) -> !fir.ptr<!fir.array<10xi32>>
171 fir.store %cst to %4 : !fir.ptr<f32>
172 %10 = fir.array_coor %9(%8) %c1 : (!fir.ptr<!fir.array<10xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
173 fir.store %c1_i32 to %10 : !fir.ref<i32>
174 fir.store %cst to %5 : !fir.ptr<f32>
175 return
176 }
177 }