[PATCH] PR middle-end/98420: Don't fold x - x to 0.0 with -frounding-math

Roger Sayle roger@nextmovesoftware.com
Thu Mar 10 23:31:13 GMT 2022


This patch addresses PR middle-end/98420, which is inappropriate constant
folding of x - x to 0.0 (in match.pd) when -frounding-math is specified.
Specifically, x - x may be -0.0 with FE_DOWNWARD as the rounding mode.

To summarize, the desired IEEE behaviour, x - x for floating point x,
(1) can't be folded to 0.0 by default, due to the possibility of NaN or Inf
(2) can be folded to 0.0 with -ffinite-math-only
(3) can't be folded to 0.0 with -ffinite-math-only -frounding-math
(4) can be folded with -ffinite-math-only -frounding-math -fno-signed-zeros

Technically, this is a regression from GCC 4.1 (according to godbolt.org)
so hopefully this patch is suitable during stage4.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures.  Ok for mainline?


2022-03-10  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	PR middle-end/98420
	* match.pd (minus @0 @0): Additional checks for -fno-rounding-math
	(the defaut) or -fno-signed-zeros.

gcc/testsuite/ChangeLog
	PR middle-end/98420
	* gcc.dg/pr98420.c: New test case.


Thanks in advance,
Roger
--

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchrm.txt
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20220310/cc202581/attachment.txt>


More information about the Gcc-patches mailing list