MIN/MAX and trapping math and NANs

Richard Biener rguenther@suse.de
Tue Apr 11 08:00:22 GMT 2023

On Sat, 1 Apr 2023, Andrew Pinski wrote:

> Hi,
>   I noticed while working on phi-opt, that MIN/MAX EXPR (and the
> corresponding RTL codes) both can return true for trapping even if
> NANs are not honored (that is -ffinite-math-only). Is this true? I
> would have assumed when -ffinite-math-only -fno-signed-zeros is used,
> then MIN/MAX would be the same as a > b ? a : b which would not cause
> a trap.
> If we think they should not trap, then I will create a patch and test
> it for GCC 14.

I think without NaNs MIN/MAX cannot raise any exceptions (I'm not
even sure whether MIN/MAX involving NaN will set invalid, but
most certainly with sNaN it will trap and return a quiet NaN?).
The C standard doesn't
document any exceptions for fmax/fmin (even with NaN), but
meanwhile there's a plethora of min/max function variants ...

I'm sure Joseph can clarify whether unconditionally returning
honor_snans (or false?) for MIN/MAX_EXPR from operation_could_trap_helper_p
would be correct.


> Thanks,
> Andrew Pinski

Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

More information about the Gcc mailing list