On Thu, Oct 29, 2026 at 9:41 PM Torbjörn Svensson via Sourceware Forge
<[email protected]> wrote:
>
> From: Torbjörn SVENSSON <[email protected]>
>
> The ifn_copysign check assumes that float and double copysign support
> go together. Split it into ifn_copysignf and ifn_copysignd to allow for
> targets that support one but not the other.
>
> Use the new checks in the tests, including cases where only float
> copysign is supported. This does not change which targets pass either
> check yet.

LGTM

> gcc/ChangeLog:
>
>         * doc/sourcebuild.texi: Document ifn_copysignf and ifn_copysignd.
>
> gcc/testsuite/ChangeLog:
>
>         * lib/target-supports.exp (check_effective_target_ifn_copysignf):
>         Rename from check_effective_target_ifn_copysign.
>         (check_effective_target_ifn_copysignd): New proc.
>         * gcc.dg/fold-copysign-1.c: Use ifn_copysignd.
>         * gcc.dg/pr55152-2.c: Likewise.
>         * gcc.dg/tree-ssa/abs-4.c: Adjust copysign checks.
>         * gcc.dg/tree-ssa/backprop-6.c: Likewise.
>         * gcc.dg/tree-ssa/copysign-signbit.c: Likewise.
>         * gcc.dg/tree-ssa/copy-sign-2.c: Use ifn_copysignf.
>         * gcc.dg/tree-ssa/pr109843.c: Likewise.
>         * gcc.dg/tree-ssa/pr112472.c: Use ifn_copysignd.
>
> Signed-off-by: Torbjörn SVENSSON <[email protected]>
> ---
>  gcc/doc/sourcebuild.texi                        |  8 ++++++--
>  gcc/testsuite/gcc.dg/fold-copysign-1.c          |  8 ++++----
>  gcc/testsuite/gcc.dg/pr55152-2.c                |  6 +++---
>  gcc/testsuite/gcc.dg/tree-ssa/abs-4.c           | 15 +++++++++------
>  gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c      | 15 +++++++++------
>  gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c     |  6 +++---
>  .../gcc.dg/tree-ssa/copysign-signbit.c          |  5 +++--
>  gcc/testsuite/gcc.dg/tree-ssa/pr109843.c        |  6 +++---
>  gcc/testsuite/gcc.dg/tree-ssa/pr112472.c        |  8 ++++----
>  gcc/testsuite/lib/target-supports.exp           | 17 ++++++++++++++---
>  10 files changed, 58 insertions(+), 36 deletions(-)
>
> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
> index 897be37e450be..c1eaf667e30dc 100644
> --- a/gcc/doc/sourcebuild.texi
> +++ b/gcc/doc/sourcebuild.texi
> @@ -2875,8 +2875,12 @@ Target is ia32 or x86_64.
>  @item xorsign
>  Target supports the xorsign optab expansion.
>
> -@item ifn_copysign
> -Target supports the copysign optab expansion of float and double for
> +@item ifn_copysignf
> +Target supports the copysign optab expansion of float for
> +both scalar and vector modes.
> +
> +@item ifn_copysignd
> +Target supports the copysign optab expansion of double for
>  both scalar and vector modes.
>
>  @end table
> diff --git a/gcc/testsuite/gcc.dg/fold-copysign-1.c 
> b/gcc/testsuite/gcc.dg/fold-copysign-1.c
> index b65c08bd9a084..c9f6fca5d2eab 100644
> --- a/gcc/testsuite/gcc.dg/fold-copysign-1.c
> +++ b/gcc/testsuite/gcc.dg/fold-copysign-1.c
> @@ -14,7 +14,7 @@ double bar (double x)
>    return __builtin_copysign (x, minuszero);
>  }
>
> -/* { dg-final { scan-tree-dump-times "__builtin_copysign" 1 "cddce1" { 
> target ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 1 "cddce1" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "= -" 1 "cddce1" { target { ! 
> ifn_copysign } } } } */
> -/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 2 "cddce1" { target { ! 
> ifn_copysign } } } } */
> +/* { dg-final { scan-tree-dump-times "__builtin_copysign" 1 "cddce1" { 
> target ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 1 "cddce1" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times "= -" 1 "cddce1" { target { ! 
> ifn_copysignd } } } } */
> +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 2 "cddce1" { target { ! 
> ifn_copysignd } } } } */
> diff --git a/gcc/testsuite/gcc.dg/pr55152-2.c 
> b/gcc/testsuite/gcc.dg/pr55152-2.c
> index 7533ab4db6011..0430fc3f5fafd 100644
> --- a/gcc/testsuite/gcc.dg/pr55152-2.c
> +++ b/gcc/testsuite/gcc.dg/pr55152-2.c
> @@ -11,6 +11,6 @@ int f(int a)
>    return (a<-a)?a:-a;
>  }
>
> -/* { dg-final { scan-tree-dump-times "\.COPYSIGN" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "ABS_EXPR" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "ABS_EXPR" 2 "optimized" { target { ! 
> ifn_copysign } } } } */
> +/* { dg-final { scan-tree-dump-times "\.COPYSIGN" 1 "optimized" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times "ABS_EXPR" 1 "optimized" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times "ABS_EXPR" 2 "optimized" { target { ! 
> ifn_copysignd } } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
> index f43018d0dff48..06482c5b967e2 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-4.c
> @@ -10,9 +10,12 @@ long double abs_ld(long double x) { return 
> __builtin_signbit(x) ? x : -x; }
>
>  /* __builtin_signbit(x) ? x : -x. Should be convert into - ABS_EXP<x> */
>  /* { dg-final { scan-tree-dump-not "signbit" "optimized"} } */
> -/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 1 "optimized" { target { 
> ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times "= -" 1 "optimized" { target { 
> ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times "= \.COPYSIGN" 2 "optimized" { target { 
> ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times "= \.COPYSIGN" 3 "optimized" { target { 
> ifn_copysign && s390*-*-* } } } } */
> -/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 3 "optimized" { target { ! 
> ifn_copysign } } } } */
> -/* { dg-final { scan-tree-dump-times "= -" 3 "optimized" { target { ! 
> ifn_copysign } } } } */
> +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 1 "optimized" { target { 
> ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times "= -" 1 "optimized" { target { 
> ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times "= \.COPYSIGN" 2 "optimized" { target { 
> ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times "= \.COPYSIGN" 3 "optimized" { target { 
> ifn_copysignd && s390*-*-* } } } } */
> +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 3 "optimized" { target { ! 
> ifn_copysignf } } } } */
> +/* { dg-final { scan-tree-dump-times "= -" 3 "optimized" { target { ! 
> ifn_copysignf } } } } */
> +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 2 "optimized" { target { 
> ifn_copysignf && { ! ifn_copysignd } } } } } */
> +/* { dg-final { scan-tree-dump-times "= -" 2 "optimized" { target { 
> ifn_copysignf && { ! ifn_copysignd } } } } } */
> +/* { dg-final { scan-tree-dump-times "= \.COPYSIGN" 1 "optimized" { target { 
> ifn_copysignf && { ! ifn_copysignd } } } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c
> index efb53f17f861c..afc3b67a170c2 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/backprop-6.c
> @@ -27,9 +27,12 @@ TEST_FUNCTION (float, f)
>  TEST_FUNCTION (double, )
>  TEST_FUNCTION (long double, l)
>
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = -} 4 "backprop" { 
> target { ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = \.COPYSIGN} 2 
> "backprop" { target { ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = ABS_EXPR <} 1 
> "backprop" { target { ifn_copysign && { ! { s390*-*-* } } } } } } */
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = \.COPYSIGN} 3 
> "backprop" { target { ifn_copysign && s390*-*-* } } } } */
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = -} 6 "backprop" { 
> target { ! ifn_copysign } } } } */
> -/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = ABS_EXPR <} 3 
> "backprop" { target { ! ifn_copysign } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = -} 4 "backprop" { 
> target { ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = \.COPYSIGN} 2 
> "backprop" { target { ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = ABS_EXPR <} 1 
> "backprop" { target { ifn_copysignd && { ! { s390*-*-* } } } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = \.COPYSIGN} 3 
> "backprop" { target { ifn_copysignd && s390*-*-* } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = -} 6 "backprop" { 
> target { ! ifn_copysignf } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = ABS_EXPR <} 3 
> "backprop" { target { ! ifn_copysignf } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = -} 5 "backprop" { 
> target { ifn_copysignf && { ! ifn_copysignd } } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = \.COPYSIGN} 1 
> "backprop" { target { ifn_copysignf && { ! ifn_copysignd } } } } } */
> +/* { dg-final { scan-tree-dump-times {Deleting[^\n]* = ABS_EXPR <} 2 
> "backprop" { target { ifn_copysignf && { ! ifn_copysignd } } } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c
> index e43bc315bef2b..9df386a39cce6 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-2.c
> @@ -11,6 +11,6 @@ float f1(float x)
>    float t = __builtin_copysignf (1.0f, -x);
>    return x * t;
>  }
> -/* { dg-final { scan-tree-dump-times "ABS" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times ".COPYSIGN" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "ABS" 2 "optimized" { target { ! 
> ifn_copysign } } } } */
> +/* { dg-final { scan-tree-dump-times "ABS" 1 "optimized" { target 
> ifn_copysignf } } } */
> +/* { dg-final { scan-tree-dump-times ".COPYSIGN" 1 "optimized" { target 
> ifn_copysignf } } } */
> +/* { dg-final { scan-tree-dump-times "ABS" 2 "optimized" { target { ! 
> ifn_copysignf } } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/copysign-signbit.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/copysign-signbit.c
> index e005d4c9819c3..5f4fb77ac8b3d 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/copysign-signbit.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/copysign-signbit.c
> @@ -28,5 +28,6 @@ float f_eq (float x, float y)
>  double d_neg (double x, double y)
>  { return __builtin_signbit (x) != __builtin_signbit (y) ? y : -y; }
>
> -/* { dg-final { scan-tree-dump-times " = \\.COPYSIGN " 6 "optimized" { 
> target ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-not "signbit" "optimized" { target 
> ifn_copysign } } } */
> +/* { dg-final { scan-tree-dump-times " = \\.COPYSIGN " 1 "optimized" { 
> target { ifn_copysignf && { ! ifn_copysignd } } } } } */
> +/* { dg-final { scan-tree-dump-times " = \\.COPYSIGN " 6 "optimized" { 
> target ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-not "signbit" "optimized" { target 
> ifn_copysignd } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109843.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/pr109843.c
> index 34e384f095b67..b77f955ea3a7a 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/pr109843.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109843.c
> @@ -72,6 +72,6 @@ float copysign9 (float x, float y)
>    return (t != t1) ? y : -y;
>  }
>
> -/* { dg-final { scan-tree-dump-not "signbit" "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "= \\.COPYSIGN" 9 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times " = -" 4 "optimized" { target 
> ifn_copysign } } } */
> +/* { dg-final { scan-tree-dump-not "signbit" "optimized" { target 
> ifn_copysignf } } } */
> +/* { dg-final { scan-tree-dump-times "= \\.COPYSIGN" 9 "optimized" { target 
> ifn_copysignf } } } */
> +/* { dg-final { scan-tree-dump-times " = -" 4 "optimized" { target 
> ifn_copysignf } } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr112472.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/pr112472.c
> index ec07effad5bee..6aae1954af45d 100644
> --- a/gcc/testsuite/gcc.dg/tree-ssa/pr112472.c
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr112472.c
> @@ -19,7 +19,7 @@ float f2(float a)
>  }
>
>  /* { dg-final { scan-tree-dump-not "= __builtin_copysign" "optimized" } } */
> -/* { dg-final { scan-tree-dump-not " double " "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times ".COPYSIGN" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times "-1.0e\\+0" 1 "optimized" { target 
> ifn_copysign } } } */
> -/* { dg-final { scan-tree-dump-times " ABS_EXPR " 1 "optimized" { target 
> ifn_copysign } } } */
> +/* { dg-final { scan-tree-dump-not " double " "optimized" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times ".COPYSIGN" 1 "optimized" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times "-1.0e\\+0" 1 "optimized" { target 
> ifn_copysignd } } } */
> +/* { dg-final { scan-tree-dump-times " ABS_EXPR " 1 "optimized" { target 
> ifn_copysignd } } } */
> diff --git a/gcc/testsuite/lib/target-supports.exp 
> b/gcc/testsuite/lib/target-supports.exp
> index 3c5dfd59f6fe7..c8f44e364925c 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -9081,12 +9081,12 @@ proc check_effective_target_xorsign { } {
>  }
>
>  # Return 1 if the target plus current options supports folding of
> -# copysign into IFN_COPYSIGN.
> +# copysign into IFN_COPYSIGN for float.
>  #
>  # This won't change for different subtargets so cache the result.
>
> -proc check_effective_target_ifn_copysign { } {
> -    return [check_cached_effective_target ifn_copysign {
> +proc check_effective_target_ifn_copysignf { } {
> +    return [check_cached_effective_target ifn_copysignf {
>        expr {
>          ([check_effective_target_x86]
>           && [is-effective-target sse])
> @@ -9103,6 +9103,17 @@ proc check_effective_target_ifn_copysign { } {
>         }}]
>  }
>
> +# Return 1 if the target plus current options supports folding of
> +# copysign into IFN_COPYSIGN for double.
> +#
> +# This won't change for different subtargets so cache the result.
> +
> +proc check_effective_target_ifn_copysignd { } {
> +    return [check_cached_effective_target ifn_copysignd {
> +       check_effective_target_ifn_copysignf
> +    }]
> +}
> +
>  # Return 1 if the target plus current options supports a vector
>  # widening summation of *short* args into *int* result, 0 otherwise.
>  #
> --
> 2.56.0
>

Reply via email to