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