Nvfortran generates simd instructions for scalar operations which cause floating exception

If the following simple program was compiled with options of -O and -Ktrap=fp, the program would produce floating exception (core dumped). The nvfortran version is 23.1-0 64-bit target on x86-64 Linux.

The nvfortran pack two dividend in one xmm register, and two divisor in another xmm register, then generates simd instruction vdivps for the two divisions. The xmm registers contain 4 packed single precision numbers, two are dividends or divisors, the others two are set 0, which cause divide by zero floating exception by vdivps.

module mtt
    type :: tt
        real ::  a, b
    contains
        procedure, pass(this) :: init => tt_init
    end type tt
contains
    subroutine tt_init(this, a, b)
        implicit none
        class(tt), intent(inout) :: this
        real, intent(in) :: a, b

        this%a = a
        this%b = b
    end subroutine tt_init
end module mtt


program test
    use mtt
    implicit none

    type(tt) :: tt1, tt2
    integer :: c

    call tt1%init(1.0, 2.0)
    call tt2%init(3.0, 4.0)
    c = tt1%a/tt2%a + tt1%b/tt2%b
    print*, c
end program test

Hi fgao1,

I talked to engineering. Since this is coming from the back-end LLVM code generator not honoring floating point safety, it may not be something we can fix directly. More likely we’d need to look to ways we can work around the issue when -Ktrap=fp is used.

I’ve filed a report, TPR #3372, and engineering will investigate.

The current work around would be to lower the LLVM opt level to O1 via “-MllvmO1”.

% nvfortran -O -Ktrap=fp test.f90 -MllvmO1 ; a.out
            0

-Mat