Skip to content

[flang][NFC] do not hard code KIND 10 and 16 in lowering tests #124966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, that's clever!

I do have a question: why use minimal kind as 4 and not 8? Kind 10 was a special kind for fp80, right? So fp64 seems to be closer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is just to get some KIND that will compile so that the rest of the tests in the files work, the kind does not really matter (the IR is not tested when 10 is not selected). I took 4 because that is our default kind.

I could also have used ifdefs, but that requires preprocessing and is less portable (and for kind16, I was not sure how to pick an ifdef).

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