Fix (fcopysign x, NEGATIVE_CONST) -> (fneg (fabs x)) simplification [PR112483]

Message ID 20231112202603.228074-2-xry111@xry111.site
State Unresolved
Headers
Series Fix (fcopysign x, NEGATIVE_CONST) -> (fneg (fabs x)) simplification [PR112483] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Xi Ruoyao Nov. 12, 2023, 8:25 p.m. UTC
  (fcopysign x, NEGATIVE_CONST) can be simplified to (fneg (fabs x)), but
a logic error in the code caused it mistakenly simplified to (fneg x)
instead.

gcc/ChangeLog:

	PR rtl-optimization/112483
	* simplify-rtx.cc (simplify_binary_operation_1) <case COPYSIGN>:
	Fix the simplification of (fcopysign x, NEGATIVE_CONST).
---

Bootstrapped and regtested on loongarch64-linux-gnu and
x86_64-linux-gnu.  Ok for trunk?

 gcc/simplify-rtx.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index 69d87579d9c..2d2e5a3c1ca 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -4392,7 +4392,7 @@  simplify_ashift:
 	  real_convert (&f1, mode, CONST_DOUBLE_REAL_VALUE (trueop1));
 	  rtx tmp = simplify_gen_unary (ABS, mode, op0, mode);
 	  if (REAL_VALUE_NEGATIVE (f1))
-	    tmp = simplify_gen_unary (NEG, mode, op0, mode);
+	    tmp = simplify_gen_unary (NEG, mode, tmp, mode);
 	  return tmp;
 	}
       if (GET_CODE (op0) == NEG || GET_CODE (op0) == ABS)