Skip to content

Commit

Permalink
[flang][NFC] do not hard code KIND 10 and 16 in lowering tests (#124966)
Browse files Browse the repository at this point in the history
KIND 10 and 16 are platform dependent and it will soon be a hard error
to use them when not available
(PR124655)

Update some tests that used them to use SELECTED_REAL_KIND + lit
conditional checks to make the tests usable on all platform.

Also update all those tests to use HFLIR lowering while modifying them
since the goal is to remove the legacy lowering at some point.
  • Loading branch information
jeanPerier authored Jan 30, 2025
1 parent 205b0bd commit 1128343
Show file tree
Hide file tree
Showing 23 changed files with 1,076 additions and 1,077 deletions.
32 changes: 11 additions & 21 deletions flang/test/Lower/Intrinsics/aint.f90
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK%if target=x86_64{{.*}} %{,CHECK-KIND10%}

! CHECK-LABEL: func @_QPaint_test(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32>{{.*}}, %[[VAL_1:.*]]: !fir.ref<f32>{{.*}}) {
! CHECK-SAME: %[[VAL_0_b:.*]]: !fir.ref<f32>{{.*}}, %[[VAL_1_b:.*]]: !fir.ref<f32>{{.*}}) {
subroutine aint_test(a, b)
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32>
! CHECK: %[[VAL_0:.*]]:2 = hlfir.declare %[[VAL_0_b]]
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_1_b]]
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]]#0 : !fir.ref<f32>
! CHECK: %[[VAL_3:.*]] = fir.call @llvm.trunc.f32(%[[VAL_2]]) {{.*}}: (f32) -> f32
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f32>
! CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_1]]#0 : f32, !fir.ref<f32>
! CHECK: return
real :: a, b
b = aint(a)
end subroutine

! CHECK-LABEL: func.func @_QPaint_test_real8(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f64> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f64>
! CHECK: %[[VAL_3:.*]] = fir.call @llvm.trunc.f64(%[[VAL_2]]) {{.*}}: (f64) -> f64
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f64>
! CHECK: return
! CHECK: }
! CHECK: fir.call @llvm.trunc.f64({{.*}}) {{.*}}: (f64) -> f64

subroutine aint_test_real8(a, b)
real(8) :: a, b
b = aint(a)
end subroutine

! CHECK-LABEL: func.func @_QPaint_test_real10(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f80> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f80> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f80>
! CHECK: %[[VAL_3:.*]] = fir.call @llvm.trunc.f80(%[[VAL_2]]) {{.*}}: (f80) -> f80
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f80>
! CHECK: return
! CHECK: }

! CHECK-KIND10-LABEL: func.func @_QPaint_test_real10(
! CHECK-KIND10: fir.call @llvm.trunc.f80({{.*}}) {{.*}}: (f80) -> f80
subroutine aint_test_real10(a, b)
real(10) :: a, b
integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10)
real(kind10) :: a, b
b = aint(a)
end subroutine

Expand Down
33 changes: 12 additions & 21 deletions flang/test/Lower/Intrinsics/anint.f90
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK%if target=x86_64{{.*}} %{,CHECK-KIND10%}

! CHECK-LABEL: func.func @_QPanint_test(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f32>
! CHECK-SAME: %[[VAL_0_b:.*]]: !fir.ref<f32> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1_b:.*]]: !fir.ref<f32> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_0:.*]]:2 = hlfir.declare %[[VAL_0_b]]
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_1_b]]
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]]#0 : !fir.ref<f32>
! CHECK: %[[VAL_3:.*]] = llvm.intr.round(%[[VAL_2]]) : (f32) -> f32
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f32>
! CHECK: hlfir.assign %[[VAL_3]] to %[[VAL_1]]#0 : f32, !fir.ref<f32>
! CHECK: return
! CHECK: }

Expand All @@ -15,30 +17,19 @@ subroutine anint_test(a, b)
end subroutine

! CHECK-LABEL: func.func @_QPanint_test_real8(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f64> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f64>
! CHECK: %[[VAL_3:.*]] = llvm.intr.round(%[[VAL_2]]) : (f64) -> f64
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f64>
! CHECK: return
! CHECK: }
! CHECK: llvm.intr.round(%{{.*}}) : (f64) -> f64

subroutine anint_test_real8(a, b)
real(8) :: a, b
b = anint(a)
end subroutine

! CHECK-LABEL: func.func @_QPanint_test_real10(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f80> {fir.bindc_name = "a"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f80> {fir.bindc_name = "b"}) {
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<f80>
! CHECK: %[[VAL_3:.*]] = llvm.intr.round(%[[VAL_2]]) : (f80) -> f80
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f80>
! CHECK: return
! CHECK: }
! CHECK-KIND10-LABEL: func.func @_QPanint_test_real10(
! CHECK-KIND10: llvm.intr.round(%{{.*}}) : (f80) -> f80

subroutine anint_test_real10(a, b)
real(10) :: a, b
integer, parameter :: kind10 = merge(10, 4, selected_real_kind(p=18).eq.10)
real(kind10) :: a, b
b = anint(a)
end subroutine

Expand Down
Loading

0 comments on commit 1128343

Please sign in to comment.