Skip to content

[Fortran] Add floating point to integer conversion test #220

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 3 commits into from
Mar 17, 2025

Conversation

ashermancinelli
Copy link
Contributor

Semantics for floating point conversions to integer types was changed in flang to use the saturated floating point intrinsics to more closely match the standard semantics in llvm-project#130686 . This tests conversions from tiny, huge, and inf to various integer types.

@ashermancinelli ashermancinelli self-assigned this Mar 13, 2025
@ashermancinelli ashermancinelli changed the title [flang] Add floating point to integer conversion test [Fortran] Add floating point to integer conversion test Mar 13, 2025
@jeanPerier jeanPerier requested review from tblah and tarunprabhu March 13, 2025 08:18
Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks for adding this test here! Works for me.

@ashermancinelli
Copy link
Contributor Author

ashermancinelli commented Mar 13, 2025

A couple notes:

  • We can remove unsigned if folks use this test suite with compilers that don't support that flag (or disable this test under some flag)
  • I wouldn't mind adding real(kind=16) support if we have a way to tell if it's supported with the current compiler

@tarunprabhu
Copy link
Contributor

* We can remove unsigned if folks use this test suite with compilers that don't support that flag (or disable this test under some flag)

I don't think the llvm-test-suite is really intended to be a general-purpose compiler test suite. Unless flang has a way to disable support for unsigned, I wouldn't worry about it.

* I wouldn't mind adding real(kind=16) support if we have a way to tell if it's supported with the current compiler

I was thinking that myself but I don't know how to check for this off the top of my head. Maybe @jeanPerier knows, or knows of someone who does.

@tblah
Copy link
Contributor

tblah commented Mar 13, 2025

I was thinking that myself but I don't know how to check for this off the top of my head. Maybe @jeanPerier knows, or knows of someone who does.

! REQUIRES: flang-supports-f128-math

EDIT: Apologies this would actually only work for a lit test.

I think for unit tests you would need to duplicate the CMake logic for f128 support. You can see examples here https://github.com/llvm/llvm-project/pull/106957/files

@ashermancinelli
Copy link
Contributor Author

Thanks @tblah! If this test suite is not trying to be portable, maybe we could use the FLANG_SUPPORT_R16 macro?

Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

This worked for me on Linux on x86. Thanks.

@ashermancinelli
Copy link
Contributor Author

ashermancinelli commented Mar 14, 2025

I split the test into two, one of which uses real(16) and is conditionally enabled.

Also, since this is just for LLVM I added a quick check for NaN -> int conversions.

Thanks for the reviews! Please LMK if there's anything else y'all would like changed.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

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

Thanks for the update.

This correctly enabled r16 support and passed on my aarch64 system.

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks

Semantics for floating point conversions to integer types was changed in flang
to use the saturated floating point intrinsics to more closely match the
standard semantics in llvm-project#130686 .
This tests conversions from tiny, huge and inf to various integer types.
I replicated the floating point conversion test for real(kind=16).
Instead of trying to keep both tests in the same source file, I broke
it into two tests and only enabled one when the fortran compiler
can compile a test program using real16.
When the utility module had the same name in both tests, we
get errors because of multiple build rules for the module.
Renamed to resolve the conflict.
Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

Does fp_convert_r16.f90 need to do the same thing as fp_convert.f90 in addition to kind=16? It looks like fp_convert.f90 is always built and run. Could we do just kind=16 in the other file then or am I missing something obvious>

@ashermancinelli
Copy link
Contributor Author

Does fp_convert_r16.f90 need to do the same thing as fp_convert.f90 in addition to kind=16?

The fp_convert_r16 test converts to some of the same types, but from real16 and also to int16 and unsigned16 - there should be no conversions that happen in both test cases. Is that what you were asking?

Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

Does fp_convert_r16.f90 need to do the same thing as fp_convert.f90 in addition to kind=16?

The fp_convert_r16 test converts to some of the same types, but from real16 and also to int16 and unsigned16 - there should be no conversions that happen in both test cases. Is that what you were asking?

Ah, sorry. I didn't notice that value in do_conversion is real(8) in one and real(16) in the other.

Thanks for clarifying. LGTM

@ashermancinelli ashermancinelli merged commit 65909a3 into llvm:main Mar 17, 2025
1 check passed
@ashermancinelli ashermancinelli deleted the ajm/fp-conversions branch March 18, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants