diff mbox series

middle-end/116891 - fix (negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)

Message ID 20241014061402.028DE13A51@imap1.dmz-prg2.suse.org
State New
Headers show
Series middle-end/116891 - fix (negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2) | expand

Commit Message

Richard Biener Oct. 14, 2024, 6:14 a.m. UTC
Transforming -fma (-a, b, -c) to fma (a, b, c) is only valid when
not rounding towards -inf or +inf as the sign of the multiplication
changes.

Bootstrap and regtest running on x86_64-unknown-linux-gnu, OK?

Richard.

	PR middle-end/116891
	* match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)):
	Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING.
---
 gcc/match.pd | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Jelinek Oct. 14, 2024, 6:53 a.m. UTC | #1
On Mon, Oct 14, 2024 at 08:14:01AM +0200, Richard Biener wrote:
> Transforming -fma (-a, b, -c) to fma (a, b, c) is only valid when
> not rounding towards -inf or +inf as the sign of the multiplication
> changes.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu, OK?
> 
> Richard.
> 
> 	PR middle-end/116891
> 	* match.pd ((negate (IFN_FNMS@3 @0 @1 @2)) -> (IFN_FMA @0 @1 @2)):
> 	Only enable for !HONOR_SIGN_DEPENDENT_ROUNDING.

Guess it would be nice to have a testcase which FAILs without the patch and
PASSes with it, but it can be added later.

So ok.

> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -9482,7 +9482,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    (IFN_FMA @0 @1 @2))
>   (simplify
>    (negate (IFN_FNMS@3 @0 @1 @2))
> -  (if (single_use (@3))
> +  (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
>     (IFN_FMA @0 @1 @2))))
>  
>  /* CLZ simplifications.  */
> -- 
> 2.43.0

	Jakub
diff mbox series

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index eff1ace87f5..b65998f201d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9482,7 +9482,7 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (IFN_FMA @0 @1 @2))
  (simplify
   (negate (IFN_FNMS@3 @0 @1 @2))
-  (if (single_use (@3))
+  (if (!HONOR_SIGN_DEPENDENT_ROUNDING (type) && single_use (@3))
    (IFN_FMA @0 @1 @2))))
 
 /* CLZ simplifications.  */