1 // RUN: fir-opt --lower-workshare --allow-unregistered-dialect %s | FileCheck %s
3 // Checks that fir.alloca is hoisted out and copyprivate'd
6 %c1 = arith.constant 1 : index
7 %c42 = arith.constant 42 : index
8 %c1_i32 = arith.constant 1 : i32
9 %alloc = fir.alloca i32
10 fir.store %c1_i32 to %alloc : !fir.ref<i32>
11 omp.workshare.loop_wrapper {
12 omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) {
13 "test.test1"(%alloc) : (!fir.ref<i32>) -> ()
17 "test.test2"(%alloc) : (!fir.ref<i32>) -> ()
23 // CHECK-LABEL: func.func private @_workshare_copy_i32(
24 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>,
25 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32>) {
26 // CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
27 // CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref<i32>
31 // CHECK-LABEL: func.func @wsfunc() {
32 // CHECK: %[[VAL_0:.*]] = fir.alloca i32
33 // CHECK: omp.single copyprivate(%[[VAL_0]] -> @_workshare_copy_i32 : !fir.ref<i32>) {
34 // CHECK: %[[VAL_1:.*]] = arith.constant 1 : i32
35 // CHECK: fir.store %[[VAL_1]] to %[[VAL_0]] : !fir.ref<i32>
36 // CHECK: omp.terminator
38 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
39 // CHECK: %[[VAL_3:.*]] = arith.constant 42 : index
40 // CHECK: omp.wsloop {
41 // CHECK: omp.loop_nest (%[[VAL_4:.*]]) : index = (%[[VAL_2]]) to (%[[VAL_3]]) inclusive step (%[[VAL_2]]) {
42 // CHECK: "test.test1"(%[[VAL_0]]) : (!fir.ref<i32>) -> ()
46 // CHECK: omp.single nowait {
47 // CHECK: "test.test2"(%[[VAL_0]]) : (!fir.ref<i32>) -> ()
48 // CHECK: omp.terminator