| 1 |
! Test forall lowering |
| 2 |
|
| 3 |
! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s |
| 4 |
|
| 5 |
!*** This FORALL construct does present a potential loop-carried dependence if |
| 6 |
!*** implemented naively (and incorrectly). The final value of a(3) must be the |
| 7 |
!*** value of a(2) before loopy begins execution added to b(2). |
| 8 |
subroutine test9(a,b,n) |
| 9 |
|
| 10 |
integer :: n |
| 11 |
real, intent(inout) :: a(n) |
| 12 |
real, intent(in) :: b(n) |
| 13 |
loopy: FORALL (i=1:n-1) |
| 14 |
a(i+1) = a(i) + b(i) |
| 15 |
END FORALL loopy |
| 16 |
end subroutine test9 |
| 17 |
|
| 18 |
! CHECK-LABEL: func @_QPtest9( |
| 19 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "a"}, |
| 20 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "b"}, |
| 21 |
! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) { |
| 22 |
! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {adapt.valuebyref, bindc_name = "i"} |
| 23 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32> |
| 24 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> i64 |
| 25 |
! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i64) -> index |
| 26 |
! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index |
| 27 |
! CHECK: %[[VAL_8:.*]] = arith.cmpi sgt, %[[VAL_6]], %[[VAL_7]] : index |
| 28 |
! CHECK: %[[VAL_9:.*]] = arith.select %[[VAL_8]], %[[VAL_6]], %[[VAL_7]] : index |
| 29 |
! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32> |
| 30 |
! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i32) -> i64 |
| 31 |
! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i64) -> index |
| 32 |
! CHECK: %[[VAL_13:.*]] = arith.constant 0 : index |
| 33 |
! CHECK: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_12]], %[[VAL_13]] : index |
| 34 |
! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_14]], %[[VAL_12]], %[[VAL_13]] : index |
| 35 |
! CHECK: %[[VAL_16:.*]] = arith.constant 1 : i32 |
| 36 |
! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i32) -> index |
| 37 |
! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32> |
| 38 |
! CHECK: %[[VAL_19:.*]] = arith.constant 1 : i32 |
| 39 |
! CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_18]], %[[VAL_19]] : i32 |
| 40 |
! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> index |
| 41 |
! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index |
| 42 |
! CHECK: %[[VAL_23:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> |
| 43 |
! CHECK: %[[VAL_24:.*]] = fir.array_load %[[VAL_0]](%[[VAL_23]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32> |
| 44 |
! CHECK: %[[VAL_25:.*]] = fir.shape %[[VAL_9]] : (index) -> !fir.shape<1> |
| 45 |
! CHECK: %[[VAL_26:.*]] = fir.array_load %[[VAL_0]](%[[VAL_25]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32> |
| 46 |
! CHECK: %[[VAL_27:.*]] = fir.shape %[[VAL_15]] : (index) -> !fir.shape<1> |
| 47 |
! CHECK: %[[VAL_28:.*]] = fir.array_load %[[VAL_1]](%[[VAL_27]]) : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32> |
| 48 |
! CHECK: %[[VAL_29:.*]] = fir.do_loop %[[VAL_30:.*]] = %[[VAL_17]] to %[[VAL_21]] step %[[VAL_22]] unordered iter_args(%[[VAL_31:.*]] = %[[VAL_24]]) -> (!fir.array<?xf32>) { |
| 49 |
! CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_30]] : (index) -> i32 |
| 50 |
! CHECK: fir.store %[[VAL_32]] to %[[VAL_3]] : !fir.ref<i32> |
| 51 |
! CHECK: %[[VAL_33:.*]] = arith.constant 1 : index |
| 52 |
! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32> |
| 53 |
! CHECK: %[[VAL_35:.*]] = fir.convert %[[VAL_34]] : (i32) -> i64 |
| 54 |
! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_35]] : (i64) -> index |
| 55 |
! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_36]], %[[VAL_33]] : index |
| 56 |
! CHECK: %[[VAL_38:.*]] = fir.array_fetch %[[VAL_26]], %[[VAL_37]] : (!fir.array<?xf32>, index) -> f32 |
| 57 |
! CHECK: %[[VAL_39:.*]] = arith.constant 1 : index |
| 58 |
! CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32> |
| 59 |
! CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i32) -> i64 |
| 60 |
! CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (i64) -> index |
| 61 |
! CHECK: %[[VAL_43:.*]] = arith.subi %[[VAL_42]], %[[VAL_39]] : index |
| 62 |
! CHECK: %[[VAL_44:.*]] = fir.array_fetch %[[VAL_28]], %[[VAL_43]] : (!fir.array<?xf32>, index) -> f32 |
| 63 |
! CHECK: %[[VAL_45:.*]] = arith.addf %[[VAL_38]], %[[VAL_44]] {{.*}}: f32 |
| 64 |
! CHECK: %[[VAL_46:.*]] = arith.constant 1 : index |
| 65 |
! CHECK: %[[VAL_47:.*]] = fir.load %[[VAL_3]] : !fir.ref<i32> |
| 66 |
! CHECK: %[[VAL_48:.*]] = arith.constant 1 : i32 |
| 67 |
! CHECK: %[[VAL_49:.*]] = arith.addi %[[VAL_47]], %[[VAL_48]] : i32 |
| 68 |
! CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i32) -> i64 |
| 69 |
! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_50]] : (i64) -> index |
| 70 |
! CHECK: %[[VAL_52:.*]] = arith.subi %[[VAL_51]], %[[VAL_46]] : index |
| 71 |
! CHECK: %[[VAL_53:.*]] = fir.array_update %[[VAL_31]], %[[VAL_45]], %[[VAL_52]] : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32> |
| 72 |
! CHECK: fir.result %[[VAL_53]] : !fir.array<?xf32> |
| 73 |
! CHECK: } |
| 74 |
! CHECK: fir.array_merge_store %[[VAL_24]], %[[VAL_54:.*]] to %[[VAL_0]] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.ref<!fir.array<?xf32>> |
| 75 |
! CHECK: return |
| 76 |
! CHECK: } |