|
| 1 | +// Tests converting `fir.do_concurrent` ops to `fir.do_loop` ops. |
| 2 | + |
| 3 | +// RUN: fir-opt --split-input-file --simplify-fir-operations %s | FileCheck %s |
| 4 | + |
| 5 | +func.func @dc_1d(%i_lb: index, %i_ub: index, %i_st: index) { |
| 6 | + fir.do_concurrent { |
| 7 | + %i = fir.alloca i32 |
| 8 | + fir.do_concurrent.loop (%i_iv) = (%i_lb) to (%i_ub) step (%i_st) { |
| 9 | + %0 = fir.convert %i_iv : (index) -> i32 |
| 10 | + fir.store %0 to %i : !fir.ref<i32> |
| 11 | + } |
| 12 | + } |
| 13 | + return |
| 14 | +} |
| 15 | + |
| 16 | +// CHECK-LABEL: func.func @dc_1d( |
| 17 | +// CHECK-SAME: %[[I_LB:[^[:space:]]+]]: index, |
| 18 | +// CHECK-SAME: %[[I_UB:[^[:space:]]+]]: index, |
| 19 | +// CHECK-SAME: %[[I_ST:[^[:space:]]+]]: index) { |
| 20 | + |
| 21 | +// CHECK: %[[I:.*]] = fir.alloca i32 |
| 22 | + |
| 23 | +// CHECK: fir.do_loop %[[I_IV:.*]] = %[[I_LB]] to %[[I_UB]] step %[[I_ST]] unordered { |
| 24 | +// CHECK: %[[I_IV_CVT:.*]] = fir.convert %[[I_IV]] : (index) -> i32 |
| 25 | +// CHECK: fir.store %[[I_IV_CVT]] to %[[I]] : !fir.ref<i32> |
| 26 | +// CHECK: } |
| 27 | + |
| 28 | +// CHECK: return |
| 29 | +// CHECK: } |
| 30 | + |
| 31 | +// ----- |
| 32 | + |
| 33 | +func.func @dc_2d(%i_lb: index, %i_ub: index, %i_st: index, |
| 34 | + %j_lb: index, %j_ub: index, %j_st: index) { |
| 35 | + llvm.br ^bb1 |
| 36 | + |
| 37 | +^bb1: |
| 38 | + fir.do_concurrent { |
| 39 | + %i = fir.alloca i32 |
| 40 | + %j = fir.alloca i32 |
| 41 | + fir.do_concurrent.loop |
| 42 | + (%i_iv, %j_iv) = (%i_lb, %j_lb) to (%i_ub, %j_ub) step (%i_st, %j_st) { |
| 43 | + %0 = fir.convert %i_iv : (index) -> i32 |
| 44 | + fir.store %0 to %i : !fir.ref<i32> |
| 45 | + |
| 46 | + %1 = fir.convert %j_iv : (index) -> i32 |
| 47 | + fir.store %1 to %j : !fir.ref<i32> |
| 48 | + } |
| 49 | + } |
| 50 | + return |
| 51 | +} |
| 52 | + |
| 53 | +// CHECK-LABEL: func.func @dc_2d( |
| 54 | +// CHECK-SAME: %[[I_LB:[^[:space:]]+]]: index, |
| 55 | +// CHECK-SAME: %[[I_UB:[^[:space:]]+]]: index, |
| 56 | +// CHECK-SAME: %[[I_ST:[^[:space:]]+]]: index, |
| 57 | +// CHECK-SAME: %[[J_LB:[^[:space:]]+]]: index, |
| 58 | +// CHECK-SAME: %[[J_UB:[^[:space:]]+]]: index, |
| 59 | +// CHECK-SAME: %[[J_ST:[^[:space:]]+]]: index) { |
| 60 | + |
| 61 | +// CHECK: %[[I:.*]] = fir.alloca i32 |
| 62 | +// CHECK: %[[J:.*]] = fir.alloca i32 |
| 63 | +// CHECK: llvm.br ^bb1 |
| 64 | + |
| 65 | +// CHECK: ^bb1: |
| 66 | +// CHECK: fir.do_loop %[[I_IV:.*]] = %[[I_LB]] to %[[I_UB]] step %[[I_ST]] unordered { |
| 67 | +// CHECK: fir.do_loop %[[J_IV:.*]] = %[[J_LB]] to %[[J_UB]] step %[[J_ST]] unordered { |
| 68 | +// CHECK: %[[I_IV_CVT:.*]] = fir.convert %[[I_IV]] : (index) -> i32 |
| 69 | +// CHECK: fir.store %[[I_IV_CVT]] to %[[I]] : !fir.ref<i32> |
| 70 | +// CHECK: %[[J_IV_CVT:.*]] = fir.convert %[[J_IV]] : (index) -> i32 |
| 71 | +// CHECK: fir.store %[[J_IV_CVT]] to %[[J]] : !fir.ref<i32> |
| 72 | +// CHECK: } |
| 73 | +// CHECK: } |
| 74 | + |
| 75 | +// CHECK: return |
| 76 | +// CHECK: } |
| 77 | + |
| 78 | +// ----- |
| 79 | + |
| 80 | +func.func @dc_2d_reduction(%i_lb: index, %i_ub: index, %i_st: index, |
| 81 | + %j_lb: index, %j_ub: index, %j_st: index) { |
| 82 | + %sum = fir.alloca i32 |
| 83 | + |
| 84 | + fir.do_concurrent { |
| 85 | + %i = fir.alloca i32 |
| 86 | + %j = fir.alloca i32 |
| 87 | + fir.do_concurrent.loop |
| 88 | + (%i_iv, %j_iv) = (%i_lb, %j_lb) to (%i_ub, %j_ub) step (%i_st, %j_st) |
| 89 | + reduce(#fir.reduce_attr<add> -> %sum : !fir.ref<i32>) { |
| 90 | + %0 = fir.convert %i_iv : (index) -> i32 |
| 91 | + fir.store %0 to %i : !fir.ref<i32> |
| 92 | + |
| 93 | + %1 = fir.convert %j_iv : (index) -> i32 |
| 94 | + fir.store %1 to %j : !fir.ref<i32> |
| 95 | + } |
| 96 | + } |
| 97 | + return |
| 98 | +} |
| 99 | + |
| 100 | +// CHECK-LABEL: func.func @dc_2d_reduction( |
| 101 | +// CHECK-SAME: %[[I_LB:[^[:space:]]+]]: index, |
| 102 | +// CHECK-SAME: %[[I_UB:[^[:space:]]+]]: index, |
| 103 | +// CHECK-SAME: %[[I_ST:[^[:space:]]+]]: index, |
| 104 | +// CHECK-SAME: %[[J_LB:[^[:space:]]+]]: index, |
| 105 | +// CHECK-SAME: %[[J_UB:[^[:space:]]+]]: index, |
| 106 | +// CHECK-SAME: %[[J_ST:[^[:space:]]+]]: index) { |
| 107 | + |
| 108 | +// CHECK: %[[I:.*]] = fir.alloca i32 |
| 109 | +// CHECK: %[[J:.*]] = fir.alloca i32 |
| 110 | +// CHECK: %[[SUM:.*]] = fir.alloca i32 |
| 111 | + |
| 112 | +// CHECK: fir.do_loop %[[I_IV:.*]] = %[[I_LB]] to %[[I_UB]] step %[[I_ST]] unordered reduce({{.*}}<add>] -> %[[SUM]] : !fir.ref<i32>) { |
| 113 | +// CHECK: fir.do_loop %[[J_IV:.*]] = %[[J_LB]] to %[[J_UB]] step %[[J_ST]] unordered reduce({{.*}}<add>] -> %[[SUM]] : !fir.ref<i32>) { |
| 114 | +// CHECK: %[[I_IV_CVT:.*]] = fir.convert %[[I_IV]] : (index) -> i32 |
| 115 | +// CHECK: fir.store %[[I_IV_CVT]] to %[[I]] : !fir.ref<i32> |
| 116 | +// CHECK: %[[J_IV_CVT:.*]] = fir.convert %[[J_IV]] : (index) -> i32 |
| 117 | +// CHECK: fir.store %[[J_IV_CVT]] to %[[J]] : !fir.ref<i32> |
| 118 | +// CHECK: fir.result |
| 119 | +// CHECK: } |
| 120 | +// CHECK: fir.result |
| 121 | +// CHECK: } |
| 122 | +// CHECK: return |
| 123 | +// CHECK: } |
0 commit comments