xref: /llvm-project/flang/test/Fir/cg-ops.fir (revision 13bd41096286305ee603428f6adf161f52981827)
1// RUN: fir-opt --split-input-file --pass-pipeline="builtin.module(cg-rewrite,cse)" %s | FileCheck %s
2
3// CHECK-LABEL: func @codegen(
4// CHECK-SAME: %[[arg:.*]]: !fir
5func.func @codegen(%addr : !fir.ref<!fir.array<?xi32>>) {
6  // CHECK: %[[zero:.*]] = arith.constant 0 : index
7  %0 = arith.constant 0 : index
8  %1 = fir.shape_shift %0, %0 : (index, index) -> !fir.shapeshift<1>
9  %2 = fir.slice %0, %0, %0 : (index, index, index) -> !fir.slice<1>
10  // CHECK: %[[box:.*]] = fircg.ext_embox %[[arg]](%[[zero]]) origin %[[zero]][%[[zero]], %[[zero]], %[[zero]]] : (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index) -> !fir.box<!fir.array<?xi32>>
11  %3 = fir.embox %addr (%1) [%2] : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>>
12  // CHECK: fircg.ext_array_coor %[[arg]](%[[zero]]) origin %[[zero]][%[[zero]], %[[zero]], %[[zero]]]<%[[zero]]> : (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index, index) -> !fir.ref<i32>
13  %4 = fir.array_coor %addr (%1) [%2] %0 : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>, !fir.slice<1>, index) -> !fir.ref<i32>
14  // CHECK: fircg.ext_rebox %[[box]](%[[zero]]) origin %[[zero]] : (!fir.box<!fir.array<?xi32>>, index, index) -> !fir.box<!fir.array<?xi32>>
15  %5 = fir.rebox %3(%1) : (!fir.box<!fir.array<?xi32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<?xi32>>
16  return
17}
18
19// -----
20
21// CHECK-LABEL: fir.global @box_global
22fir.global @box_global : !fir.box<!fir.array<?xi32>> {
23  // CHECK: %[[arr:.*]] = fir.zero_bits !fir.ref
24  %arr = fir.zero_bits !fir.ref<!fir.array<?xi32>>
25  // CHECK: %[[zero:.*]] = arith.constant 0 : index
26  %0 = arith.constant 0 : index
27  %1 = fir.shape_shift %0, %0 : (index, index) -> !fir.shapeshift<1>
28  %2 = fir.slice %0, %0, %0 : (index, index, index) -> !fir.slice<1>
29  // CHECK: fircg.ext_embox %[[arr]](%[[zero]]) origin %[[zero]][%[[zero]], %[[zero]], %[[zero]]] : (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index) -> !fir.box<!fir.array<?xi32>>
30  %3 = fir.embox %arr (%1) [%2] : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>>
31  fir.has_value %3 : !fir.box<!fir.array<?xi32>>
32}
33
34// -----
35
36// fir.embox with slice with substr
37
38// CHECK-LABEL: func @codegen(
39// CHECK-SAME: %[[arg:.*]]: !fir
40func.func @codegen(%addr : !fir.ref<!fir.array<?xi32>>) {
41  // CHECK: %[[zero:.*]] = arith.constant 0 : index
42  %0 = arith.constant 0 : index
43  %1 = fir.shape_shift %0, %0 : (index, index) -> !fir.shapeshift<1>
44  %2 = fir.slice %0, %0, %0 substr %0, %0: (index, index, index, index, index) -> !fir.slice<1>
45  // CHECK: %[[box:.*]] = fircg.ext_embox %[[arg]](%[[zero]]) origin %[[zero]][%[[zero]], %[[zero]], %[[zero]]] substr %[[zero]], %[[zero]] : (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index, index, index) -> !fir.box<!fir.array<?xi32>>
46  %3 = fir.embox %addr (%1) [%2] : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>>
47  return
48}
49
50// -----
51
52// fir.rebox with slice with substr
53
54// CHECK-LABEL: func @codegen(
55// CHECK-SAME: %[[arg:.*]]: !fir
56func.func @codegen(%addr : !fir.box<!fir.array<?xf32>>) {
57  %c0 = arith.constant 0 : index
58  %c1 = arith.constant 1 : index
59  %c10 = arith.constant 10 : index
60  %0 = fir.slice %c10, %c1, %c1 substr %c1, %c1: (index, index, index, index, index) -> !fir.slice<1>
61  %1 = fir.shift %c0 : (index) -> !fir.shift<1>
62  %2 = fir.rebox %addr(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
63  return
64}
65
66// CHECK: %{{.*}} = fircg.ext_rebox %[[arg]] origin %{{.*}}[%{{.*}}, %{{.*}}, %{{.*}}] substr %{{.*}}, %{{.*}} : (!fir.box<!fir.array<?xf32>>, index, index, index, index, index, index) -> !fir.box<!fir.array<?xf32>>
67