On 7/23/2026 2:59 AM, Richard Biener wrote:
On Thu, Jul 23, 2026 at 9:12 AM Eikansh Gupta
<[email protected]> wrote:
Fold (signbit (x) cmp1 0) cmp (signbit (y) cmp2 0) ? y : -y
to copysign (y, +-x).  The result keeps the magnitude of Y and takes its
sign from X (or -X).  Emitted as IFN_COPYSIGN when the target supports it.

         PR tree-optimization/109843

gcc/ChangeLog:

         * match.pd ((signbit (x) cmp 0) cmp (signbit (y) cmp 0) ? y : -y):
         New simplification to copysign (y, +-x).

gcc/testsuite/ChangeLog:

         * gcc.dg/tree-ssa/pr109843.c: New test.

Signed-off-by: Eikansh Gupta <[email protected]>
---
  gcc/match.pd                             | 20 +++++++
  gcc/testsuite/gcc.dg/tree-ssa/pr109843.c | 76 ++++++++++++++++++++++++
  2 files changed, 96 insertions(+)
  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr109843.c

diff --git a/gcc/match.pd b/gcc/match.pd
index d1a12c35ed3..59ea0e1cc0c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9864,6 +9864,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       (abs @0)
       (negate (abs @0))))))

+/* (signbit (x) cmp1 0) cmp (signbit (y) cmp2 0) ? y : -y
+   -> copysign (y, +-x).  */
+#if GIMPLE
+(for cmp (eq ne)
+ (for icmp1 (eq ne)
+  (for icmp2 (eq ne)
+   (for sign (SIGNBIT)
That's an awful a lot of combinations (2*2*2*4)

+    (simplify
+     (cond (cmp:c (icmp1 (sign @0) integer_zerop)
Plus :c here.

I wonder where the pattern request comes from ...
Probably not spec given Andrea has been tagging things she finds with spec when relevant.

Are you objecting to the number of patterns this generates, or just noting that it's a bunch?

jeff


Reply via email to