Files
TheRock/compiler/amd-llvm/flang/test/Lower/OpenMP/atomic-compare.f90
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

143 lines
7.1 KiB
Fortran

! This test checks lowering of atomic compare constructs.
! RUN: bbc %openmp_flags -fopenmp-version=51 -emit-hlfir %s -o - | FileCheck %s
! RUN: %flang_fc1 -emit-hlfir %openmp_flags -fopenmp-version=51 %s -o - | FileCheck %s
! CHECK-LABEL: func.func @_QPatomic_compare_int_eq(
! CHECK-SAME: %[[X:.*]]: !fir.ref<i32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<i32> {fir.bindc_name = "e"},
! CHECK-SAME: %[[D:.*]]: !fir.ref<i32> {fir.bindc_name = "d"})
! CHECK: %[[D_DECL:.*]]:2 = hlfir.declare %[[D]] {{.*}}
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<i32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<i32> {
! CHECK: ^bb0(%[[XVAL:.*]]: i32):
! CHECK: %[[CMP:.*]] = arith.cmpi eq, %[[XVAL]], %[[EVAL]] : i32
! CHECK: %[[DVAL:.*]] = fir.load %[[D_DECL]]#0 : !fir.ref<i32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[DVAL]], %[[XVAL]] : i32
! CHECK: omp.yield(%[[SEL]] : i32)
! CHECK: }
subroutine atomic_compare_int_eq(x, e, d)
integer :: x, e, d
!$omp atomic compare
if (x .eq. e) x = d
end
! CHECK-LABEL: func.func @_QPatomic_compare_float_eq(
! CHECK-SAME: %[[X:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<f32> {fir.bindc_name = "e"},
! CHECK-SAME: %[[D:.*]]: !fir.ref<f32> {fir.bindc_name = "d"})
! CHECK: %[[D_DECL:.*]]:2 = hlfir.declare %[[D]] {{.*}}
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<f32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<f32> {
! CHECK: ^bb0(%[[XVAL:.*]]: f32):
! CHECK: %[[CMP:.*]] = arith.cmpf oeq, %[[XVAL]], %[[EVAL]] fastmath<contract> : f32
! CHECK: %[[DVAL:.*]] = fir.load %[[D_DECL]]#0 : !fir.ref<f32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[DVAL]], %[[XVAL]] : f32
! CHECK: omp.yield(%[[SEL]] : f32)
! CHECK: }
subroutine atomic_compare_float_eq(x, e, d)
real :: x, e, d
!$omp atomic compare
if (x .eq. e) x = d
end
! CHECK-LABEL: func.func @_QPatomic_compare_complex_eq(
! CHECK-SAME: %[[X:.*]]: !fir.ref<complex<f32>> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<complex<f32>> {fir.bindc_name = "e"},
! CHECK-SAME: %[[D:.*]]: !fir.ref<complex<f32>> {fir.bindc_name = "d"})
! CHECK: %[[D_DECL:.*]]:2 = hlfir.declare %[[D]] {{.*}}
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<complex<f32>>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<complex<f32>> {
! CHECK: ^bb0(%[[XVAL:.*]]: complex<f32>):
! CHECK: %[[CMP:.*]] = fir.cmpc "oeq", %[[XVAL]], %[[EVAL]] {fastmath = #arith.fastmath<contract>} : complex<f32>
! CHECK: %[[DVAL:.*]] = fir.load %[[D_DECL]]#0 : !fir.ref<complex<f32>>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[DVAL]], %[[XVAL]] : complex<f32>
! CHECK: omp.yield(%[[SEL]] : complex<f32>)
! CHECK: }
subroutine atomic_compare_complex_eq(x, e, d)
complex :: x, e, d
!$omp atomic compare
if (x .eq. e) x = d
end
! CHECK-LABEL: func.func @_QPatomic_compare_int_lt(
! CHECK-SAME: %[[X:.*]]: !fir.ref<i32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<i32> {fir.bindc_name = "e"})
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<i32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<i32> {
! CHECK: ^bb0(%[[XVAL:.*]]: i32):
! CHECK: %[[CMP:.*]] = arith.cmpi slt, %[[XVAL]], %[[EVAL]] : i32
! CHECK: %[[EVAL2:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<i32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[EVAL2]], %[[XVAL]] : i32
! CHECK: omp.yield(%[[SEL]] : i32)
! CHECK: }
subroutine atomic_compare_int_lt(x, e)
integer :: x, e
!$omp atomic compare
if (x .lt. e) x = e
end
! CHECK-LABEL: func.func @_QPatomic_compare_int_gt(
! CHECK-SAME: %[[X:.*]]: !fir.ref<i32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<i32> {fir.bindc_name = "e"})
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<i32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<i32> {
! CHECK: ^bb0(%[[XVAL:.*]]: i32):
! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[XVAL]], %[[EVAL]] : i32
! CHECK: %[[EVAL2:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<i32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[EVAL2]], %[[XVAL]] : i32
! CHECK: omp.yield(%[[SEL]] : i32)
! CHECK: }
subroutine atomic_compare_int_gt(x, e)
integer :: x, e
!$omp atomic compare
if (x .gt. e) x = e
end
! CHECK-LABEL: func.func @_QPatomic_compare_float_lt(
! CHECK-SAME: %[[X:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<f32> {fir.bindc_name = "e"})
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<f32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<f32> {
! CHECK: ^bb0(%[[XVAL:.*]]: f32):
! CHECK: %[[CMP:.*]] = arith.cmpf olt, %[[XVAL]], %[[EVAL]] fastmath<contract> : f32
! CHECK: %[[EVAL2:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<f32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[EVAL2]], %[[XVAL]] : f32
! CHECK: omp.yield(%[[SEL]] : f32)
! CHECK: }
subroutine atomic_compare_float_lt(x, e)
real :: x, e
!$omp atomic compare
if (x .lt. e) x = e
end
! CHECK-LABEL: func.func @_QPatomic_compare_float_gt(
! CHECK-SAME: %[[X:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[E:.*]]: !fir.ref<f32> {fir.bindc_name = "e"})
! CHECK: %[[E_DECL:.*]]:2 = hlfir.declare %[[E]] {{.*}}
! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {{.*}}
! CHECK: %[[EVAL:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<f32>
! CHECK: omp.atomic.compare memory_order(relaxed) %[[X_DECL]]#0 : !fir.ref<f32> {
! CHECK: ^bb0(%[[XVAL:.*]]: f32):
! CHECK: %[[CMP:.*]] = arith.cmpf ogt, %[[XVAL]], %[[EVAL]] fastmath<contract> : f32
! CHECK: %[[EVAL2:.*]] = fir.load %[[E_DECL]]#0 : !fir.ref<f32>
! CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[EVAL2]], %[[XVAL]] : f32
! CHECK: omp.yield(%[[SEL]] : f32)
! CHECK: }
subroutine atomic_compare_float_gt(x, e)
real :: x, e
!$omp atomic compare
if (x .gt. e) x = e
end