|
| 1 | +// Test hlfir.elemental code generation with a dynamic check |
| 2 | +// for empty result array |
| 3 | +// RUN: fir-opt %s --bufferize-hlfir=opt-empty-elementals=true | FileCheck %s |
| 4 | + |
| 5 | +func.func @test(%v: i32, %e0: i32, %e1: i32, %e2: i64, %e3: i64) { |
| 6 | + %shape = fir.shape %e0, %e1, %e2, %e3 : (i32, i32, i64, i64) -> !fir.shape<4> |
| 7 | + %result = hlfir.elemental %shape : (!fir.shape<4>) -> !hlfir.expr<?x?x?x?xi32> { |
| 8 | + ^bb0(%arg0: index, %arg1: index, %arg2: index, %arg3: index): |
| 9 | + hlfir.yield_element %v : i32 |
| 10 | + } |
| 11 | + return |
| 12 | +} |
| 13 | +// CHECK-LABEL: func.func @test( |
| 14 | +// CHECK-SAME: %[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32, %[[VAL_2:.*]]: i32, |
| 15 | +// CHECK-SAME: %[[VAL_3:.*]]: i64, %[[VAL_4:.*]]: i64) { |
| 16 | +// CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (i32, i32, i64, i64) -> !fir.shape<4> |
| 17 | +// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_1]] : (i32) -> index |
| 18 | +// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (i32) -> index |
| 19 | +// CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_3]] : (i64) -> index |
| 20 | +// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_4]] : (i64) -> index |
| 21 | +// CHECK: %[[VAL_10:.*]] = fir.allocmem !fir.array<?x?x?x?xi32>, %[[VAL_6]], %[[VAL_7]], %[[VAL_8]], %[[VAL_9]] {bindc_name = ".tmp.array", uniq_name = ""} |
| 22 | +// CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_10]](%[[VAL_5]]) {uniq_name = ".tmp.array"} : (!fir.heap<!fir.array<?x?x?x?xi32>>, !fir.shape<4>) -> (!fir.box<!fir.array<?x?x?x?xi32>>, !fir.heap<!fir.array<?x?x?x?xi32>>) |
| 23 | +// CHECK: %[[VAL_12:.*]] = arith.constant true |
| 24 | +// CHECK: %[[VAL_13:.*]] = arith.constant false |
| 25 | +// CHECK: %[[C0_1:.*]] = arith.constant 0 : index |
| 26 | +// CHECK: %[[VAL_15:.*]] = arith.cmpi eq, %[[VAL_6]], %[[C0_1]] : index |
| 27 | +// CHECK: %[[VAL_16:.*]] = arith.ori %[[VAL_13]], %[[VAL_15]] : i1 |
| 28 | +// CHECK: %[[C0_2:.*]] = arith.constant 0 : index |
| 29 | +// CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_7]], %[[C0_2]] : index |
| 30 | +// CHECK: %[[VAL_18:.*]] = arith.ori %[[VAL_16]], %[[VAL_17]] : i1 |
| 31 | +// CHECK: %[[C0_3:.*]] = arith.constant 0 : index |
| 32 | +// CHECK: %[[VAL_19:.*]] = arith.cmpi eq, %[[VAL_8]], %[[C0_3]] : index |
| 33 | +// CHECK: %[[VAL_20:.*]] = arith.ori %[[VAL_18]], %[[VAL_19]] : i1 |
| 34 | +// CHECK: %[[C0_4:.*]] = arith.constant 0 : index |
| 35 | +// CHECK: %[[VAL_21:.*]] = arith.cmpi eq, %[[VAL_9]], %[[C0_4]] : index |
| 36 | +// CHECK: %[[VAL_22:.*]] = arith.ori %[[VAL_20]], %[[VAL_21]] : i1 |
| 37 | +// CHECK: %[[VAL_23:.*]] = arith.select %[[VAL_22]], %[[C0_1]], %[[VAL_6]] : index |
| 38 | +// CHECK: %[[VAL_24:.*]] = arith.select %[[VAL_22]], %[[C0_2]], %[[VAL_7]] : index |
| 39 | +// CHECK: %[[VAL_25:.*]] = arith.select %[[VAL_22]], %[[C0_3]], %[[VAL_8]] : index |
| 40 | +// CHECK: %[[VAL_26:.*]] = arith.select %[[VAL_22]], %[[C0_4]], %[[VAL_9]] : index |
| 41 | +// CHECK: %[[VAL_27:.*]] = arith.constant 1 : index |
| 42 | +// CHECK: fir.do_loop %[[VAL_28:.*]] = %[[VAL_27]] to %[[VAL_26]] step %[[VAL_27]] { |
| 43 | +// CHECK: fir.do_loop %[[VAL_29:.*]] = %[[VAL_27]] to %[[VAL_25]] step %[[VAL_27]] { |
| 44 | +// CHECK: fir.do_loop %[[VAL_30:.*]] = %[[VAL_27]] to %[[VAL_24]] step %[[VAL_27]] { |
| 45 | +// CHECK: fir.do_loop %[[VAL_31:.*]] = %[[VAL_27]] to %[[VAL_23]] step %[[VAL_27]] { |
| 46 | +// CHECK: %[[VAL_32:.*]] = hlfir.designate %[[VAL_11]]#0 (%[[VAL_31]], %[[VAL_30]], %[[VAL_29]], %[[VAL_28]]) : (!fir.box<!fir.array<?x?x?x?xi32>>, index, index, index, index) -> !fir.ref<i32> |
| 47 | +// CHECK: hlfir.assign %[[VAL_0]] to %[[VAL_32]] temporary_lhs : i32, !fir.ref<i32> |
| 48 | +// CHECK: } |
| 49 | +// CHECK: } |
| 50 | +// CHECK: } |
| 51 | +// CHECK: } |
| 52 | +// CHECK: %[[VAL_33:.*]] = fir.undefined tuple<!fir.box<!fir.array<?x?x?x?xi32>>, i1> |
| 53 | +// CHECK: %[[VAL_34:.*]] = fir.insert_value %[[VAL_33]], %[[VAL_12]], [1 : index] : (tuple<!fir.box<!fir.array<?x?x?x?xi32>>, i1>, i1) -> tuple<!fir.box<!fir.array<?x?x?x?xi32>>, i1> |
| 54 | +// CHECK: %[[VAL_35:.*]] = fir.insert_value %[[VAL_34]], %[[VAL_11]]#0, [0 : index] : (tuple<!fir.box<!fir.array<?x?x?x?xi32>>, i1>, !fir.box<!fir.array<?x?x?x?xi32>>) -> tuple<!fir.box<!fir.array<?x?x?x?xi32>>, i1> |
| 55 | +// CHECK: return |
| 56 | +// CHECK: } |
0 commit comments