1 // Test hlfir.forall_index operation parse, verify (no errors), unparse,
2 // and canonicalization.
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
4 // RUN: fir-opt -canonicalize %s | FileCheck %s --check-prefix=CANONICALIZATION
6 func.func @forall_index(%x: !fir.ref<!fir.array<10xf32>>, %y: !fir.ref<!fir.array<10xf32>>) {
7 %c1 = arith.constant 1 : index
8 %c10 = arith.constant 10 : index
10 hlfir.yield %c1 : index
12 hlfir.yield %c10 : index
14 %i = hlfir.forall_index "i" %arg0 : (i64) -> !fir.ref<i64>
16 %ival = fir.load %i : !fir.ref<i64>
17 %yi = hlfir.designate %y(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
18 hlfir.yield %yi : !fir.ref<f32>
20 %ival = fir.load %i : !fir.ref<i64>
21 %xi = hlfir.designate %x(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
22 hlfir.yield %xi : !fir.ref<f32>
27 // CHECK-LABEL: func.func @forall_index(
28 // CHECK: hlfir.forall lb {
30 // CHECK: } (%[[VAL_4:.*]]: i64) {
31 // CHECK: hlfir.forall_index "i" %[[VAL_4]] : (i64) -> !fir.ref<i64>
33 // CANONICALIZATION-LABEL: func.func @forall_index(
34 // CANONICALIZATION: hlfir.forall lb {
35 // CANONICALIZATION: } ub {
36 // CANONICALIZATION: } (%[[VAL_4:.*]]: i64) {
37 // CANONICALIZATION-NOT: hlfir.forall_index
38 // CANONICALIZATION: hlfir.designate %{{.*}} (%[[VAL_4]]) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
39 // CANONICALIZATION: hlfir.designate %{{.*}} (%[[VAL_4]]) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
41 func.func @forall_index_do_not_canonicalize(%x: !fir.ref<!fir.array<10xf32>>, %y: !fir.ref<!fir.array<10xf32>>) {
42 %c1 = arith.constant 1 : index
43 %c10 = arith.constant 10 : index
45 hlfir.yield %c1 : index
47 hlfir.yield %c10 : index
49 %i = hlfir.forall_index "i" %arg0 : (i64) -> !fir.ref<i64>
51 %res = fir.call @taking_address(%i) : (!fir.ref<i64>) -> f32
52 hlfir.yield %res : f32
54 %ival = fir.load %i : !fir.ref<i64>
55 %xi = hlfir.designate %x(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
56 hlfir.yield %xi : !fir.ref<f32>
61 // CHECK-LABEL: func.func @forall_index_do_not_canonicalize(
62 // CHECK: hlfir.forall lb {
64 // CHECK: } (%[[VAL_4:.*]]: i64) {
65 // CHECK: hlfir.forall_index "i" %[[VAL_4]] : (i64) -> !fir.ref<i64>
67 // CANONICALIZATION-LABEL: func.func @forall_index_do_not_canonicalize(
68 // CANONICALIZATION: %[[VAL_5:.*]] = hlfir.forall_index "i" %[[VAL_4:.*]] : (i64) -> !fir.ref<i64>
69 // CANONICALIZATION: fir.call @taking_address(%[[VAL_5]]) : (!fir.ref<i64>) -> f32
70 // CANONICALIZATION: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
71 // CANONICALIZATION: hlfir.designate %{{.*}} (%[[VAL_6]]) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>