Skip to content
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

flang-new 19.0.0 bug: nan > 0, nan > 1 #89529

Open
zaikunzhang opened this issue Apr 21, 2024 · 1 comment
Open

flang-new 19.0.0 bug: nan > 0, nan > 1 #89529

zaikunzhang opened this issue Apr 21, 2024 · 1 comment
Labels
flang Flang issues not falling into any other category

Comments

@zaikunzhang
Copy link

zaikunzhang commented Apr 21, 2024

Hi,

This is a bug of flang-new 19.0.0, when invoked with -Ofast (This is not recommended in general. I know).

Code (latest version available at https://github.com/zequipe/test_compiler/blob/master/test_flang_nan.f90):

! test_flang_nan
program test_flang_nan
use ieee_arithmetic, only : ieee_value, ieee_signaling_nan, ieee_quiet_nan
! The problem occurs with REAL64 and REAL32, not REAL16 or REAL128.
use iso_fortran_env, only : RP => REAL32 !REAL64

implicit none
real(RP) :: nan

nan = ieee_value(0.0_RP, ieee_signaling_nan)
! nan = ieee_value(0.0_RP, ieee_quiet_nan)  ! The same problem

print *, nan > 0, nan > 1, nan < 0, nan < 1

if (nan > 0 .or. nan > 1 .or. nan < 0 .or. nan < 1) then
    error stop 1
end if

end program test_flang_nan

Test:

uname -a && flang --version && flang -Ofast test_flang_nan.f90 && ./a.out

Result:

Linux 6.5.0-28-generic #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr  4 14:39:20 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
flang-new version 19.0.0git (git@github.com:llvm/llvm-project.git 37c175af955f0aeab67e8c553a0a47b2ed0fdba2)
Target: x86_64-unknown-linux-gnu
Thread model: posix
 T T F F
Fortran ERROR STOP: code 1

IEEE arithmetic exceptions signaled: INVALID

Thank you for taking a look.

@EugeneZelenko EugeneZelenko added flang Flang issues not falling into any other category and removed new issue labels Apr 21, 2024
@hakostra
Copy link

Just a casual Fortran programmer here, I'm not a Flang/LLVM developer.

The first to do is to read the manpage for flang and what it says about -Ofast:

-Ofast in Flang means -O3 -ffast-math -fstack-arrays.

-ffast-math means the following:
-fno-honor-infinities
-fno-honor-nans
-fassociative-math
-freciprocal-math
-fapprox-func
-fno-signed-zeros
-ffp-contract=fast

In this very particular example you use NaN's. The -no-honor-nans flag description is:

Allow floating-point optimizations that assume arguments and results are not NaNs

I.e. you are, by using -Ofast, telling the compiler you do not have NaN's in your code. So I think the compiler is completely correct here. If you need standard-conforming maths, do not use -Ofast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

3 participants