Incorrect floating point exception (divide-by-zero), nvfortran 22.5

The following code raises a floating point exception when compiled with -Ktrap=divz -O2.

MODULE m1
CONTAINS
    SUBROUTINE s1(r1,r2,r3)
        DOUBLE PRECISION r1,r2,r3
        DOUBLE PRECISION r4,r5,r6
        DOUBLE PRECISION r7,r8,r9
        INTRINSIC ABS, ATAN, COS, SIN
        PRINT '(6(ES23.16,","))',r1,r2,r3
        r4 = r1
        r5 = r2
        r6 = r3
        PRINT '(3ES24.16)',r4,r5,r6
        PRINT '(2ES24.16)',ABS(r5-r4),ABS(r6)
        PRINT *,ABS(r5-r4).LE.ABS(r6)
        IF(ABS(r5 - r4).LE.ABS(r6))THEN
            r7 = 1.0D0
        ELSE
            r7 = ATAN(r6/(r5 - r4))
        ENDIF
        PRINT*,'check 1'
        r8 = COS(r7)
        r9 = SIN(r7)
        PRINT*,'check 2'
        r4 = r8
        PRINT*,'check 3'
    END
END MODULE m1
PROGRAM p1
    USE m1
    CALL s1(0D0,0D0,1D0)
END
$ nvfortran -V
nvfortran 22.5-0 64-bit target on x86-64 Linux -tp haswell
$ nvfortran -Ktrap=divz -O2 code.f90 && ./a.out 
 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0000000000000000E+00,
  0.0000000000000000E+00  0.0000000000000000E+00  1.0000000000000000E+00
  0.0000000000000000E+00  1.0000000000000000E+00
  T
Floating point exception (core dumped)

It seems to work with lower optimisation -Ktrap=div -O1:

$ nvfortran -Ktrap=divz -O1 code.f90 && ./a.out 
 0.0000000000000000E+00, 0.0000000000000000E+00, 1.0000000000000000E+00,
  0.0000000000000000E+00  0.0000000000000000E+00  1.0000000000000000E+00
  0.0000000000000000E+00  1.0000000000000000E+00
  T
 check 1
 check 2
 check 3

Thanks Andrew.

I filed this one as TPR #31986 and sent it to engineering for investigation.

-Mat