xref: /llvm-project/flang/test/Lower/OpenMP/parallel-reduction-complex-mul.f90 (revision c4204c0b29a6721267b1bcbaeedd7b1118e42396)
1221f438aSMats Petersson! RUN: bbc -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
2221f438aSMats Petersson! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
3221f438aSMats Petersson
4221f438aSMats Petersson!CHECK-LABEL: omp.declare_reduction
5*c4204c0bSjeanPerier!CHECK-SAME: @[[RED_NAME:.*]] : complex<f64> init {
6*c4204c0bSjeanPerier!CHECK: ^bb0(%{{.*}}: complex<f64>):
7221f438aSMats Petersson!CHECK:  %[[C0_1:.*]] = arith.constant 1.000000e+00 : f64
8221f438aSMats Petersson!CHECK:  %[[C0_2:.*]] = arith.constant 0.000000e+00 : f64
9*c4204c0bSjeanPerier!CHECK:  %[[UNDEF:.*]] = fir.undefined complex<f64>
10221f438aSMats Petersson!CHECK:  %[[RES_1:.*]] = fir.insert_value %[[UNDEF]], %[[C0_1]], [0 : index]
11221f438aSMats Petersson!CHECK:  %[[RES_2:.*]] = fir.insert_value %[[RES_1]], %[[C0_2]], [1 : index]
12*c4204c0bSjeanPerier!CHECK:  omp.yield(%[[RES_2]] : complex<f64>)
13221f438aSMats Petersson!CHECK: } combiner {
14*c4204c0bSjeanPerier!CHECK: ^bb0(%[[ARG0:.*]]: complex<f64>, %[[ARG1:.*]]: complex<f64>):
15*c4204c0bSjeanPerier!CHECK:  %[[RES:.*]] = fir.mulc %[[ARG0]], %[[ARG1]] {{.*}}: complex<f64>
16*c4204c0bSjeanPerier!CHECK:  omp.yield(%[[RES]] : complex<f64>)
17221f438aSMats Petersson!CHECK: }
18221f438aSMats Petersson
19221f438aSMats Petersson!CHECK-LABEL: func.func @_QPsimple_complex_mul
20*c4204c0bSjeanPerier!CHECK:  %[[CREF:.*]] = fir.alloca complex<f64> {bindc_name = "c", {{.*}}}
21*c4204c0bSjeanPerier!CHECK:  %[[C_DECL:.*]]:2 = hlfir.declare %[[CREF]] {uniq_name = "_QFsimple_complex_mulEc"} : (!fir.ref<complex<f64>>) -> (!fir.ref<complex<f64>>, !fir.ref<complex<f64>>)
22221f438aSMats Petersson!CHECK:  %[[C_START_RE:.*]] = arith.constant 0.000000e+00 : f64
23221f438aSMats Petersson!CHECK:  %[[C_START_IM:.*]] = arith.constant 0.000000e+00 : f64
24*c4204c0bSjeanPerier!CHECK:  %[[UNDEF_1:.*]] = fir.undefined complex<f64>
25221f438aSMats Petersson!CHECK:  %[[VAL_1:.*]] = fir.insert_value %[[UNDEF_1]], %[[C_START_RE]], [0 : index]
26221f438aSMats Petersson!CHECK:  %[[VAL_2:.*]] = fir.insert_value %[[VAL_1]], %[[C_START_IM]], [1 : index]
27*c4204c0bSjeanPerier!CHECK:  hlfir.assign %[[VAL_2]] to %[[C_DECL]]#0 : complex<f64>, !fir.ref<complex<f64>>
28*c4204c0bSjeanPerier!CHECK:  omp.parallel reduction(@[[RED_NAME]] %[[C_DECL]]#0 -> %[[PRV:.+]] : !fir.ref<complex<f64>>) {
29*c4204c0bSjeanPerier!CHECK:    %[[P_DECL:.+]]:2 = hlfir.declare %[[PRV]] {{.*}} : (!fir.ref<complex<f64>>) -> (!fir.ref<complex<f64>>, !fir.ref<complex<f64>>)
30*c4204c0bSjeanPerier!CHECK:    %[[LPRV:.+]] = fir.load %[[P_DECL]]#0 : !fir.ref<complex<f64>>
31221f438aSMats Petersson!CHECK:    %[[C_INCR_RE:.*]] = arith.constant 1.000000e+00 : f64
32221f438aSMats Petersson!CHECK:    %[[C_INCR_IM:.*]] = arith.constant -2.000000e+00 : f64
33*c4204c0bSjeanPerier!CHECK:    %[[UNDEF_2:.*]] = fir.undefined complex<f64>
34221f438aSMats Petersson!CHECK:    %[[INCR_1:.*]] = fir.insert_value %[[UNDEF_2]], %[[C_INCR_RE]], [0 : index]
35221f438aSMats Petersson!CHECK:    %[[INCR_2:.*]] = fir.insert_value %[[INCR_1]], %[[C_INCR_IM]], [1 : index]
36*c4204c0bSjeanPerier!CHECK:    %[[RES:.+]] = fir.mulc %[[LPRV]], %[[INCR_2]] {{.*}} : complex<f64>
37*c4204c0bSjeanPerier!CHECK:    hlfir.assign %[[RES]] to %[[P_DECL]]#0 : complex<f64>, !fir.ref<complex<f64>>
38221f438aSMats Petersson!CHECK:    omp.terminator
39221f438aSMats Petersson!CHECK:  }
40221f438aSMats Petersson!CHECK: return
41221f438aSMats Peterssonsubroutine simple_complex_mul
42221f438aSMats Petersson    complex(8) :: c
43221f438aSMats Petersson    c = 0
44221f438aSMats Petersson
45221f438aSMats Petersson    !$omp parallel reduction(*:c)
46221f438aSMats Petersson    c = c * cmplx(1, -2)
47221f438aSMats Petersson    !$omp end parallel
48221f438aSMats Petersson
49221f438aSMats Petersson    print *, c
50221f438aSMats Peterssonend subroutine
51