@rearnsha wrote in 
https://forge.sourceware.org/gcc/gcc/pulls/262#issuecomment-8077:

> I think I must be missing something. If I compile
> 
> ```text
> double f (double a, double b)
> {
>   return __builtin_copysign (a, b);
> }
> ```
> 
> with `-O2 -march=armv7-a+fp -mfloat-abi=hard` on today's trunk compiler, I get
> 
> ```text
> f:
>         @ args = 0, pretend = 0, frame = 0
>         @ frame_needed = 0, uses_anonymous_args = 0
>         @ link register save eliminated.
>         vmov    r3, s3  @ int
>         vabs.f64        d0, d0
>         cmp     r3, #0
>         vneglt.f64      d0, d0
>         bx      lr
>         .size   f, .-f
>         .ident  "GCC: (review) 17.0.0 20261023 (experimental)"
> ```
> 
> So what is this patch adding?

That example already produces the same sequence without the patch.

I started looking at this because of the testsuite failures below (seen with 
r17-5743-ge33129b871c302).
I found that copysignsf3 and copysigndf3 in arm.md were only enabled for soft 
float, so I added implementations for hardware floating point.

As I understand it, your example already works through expand_copysign_absneg 
in optabs.cc, whereas these expanders also make the support available to the 
optimizations checked by the failing tests.

The soft-float failures are addressed by correcting the test checks; the 
hardware floating-point cases also need the new expanders.

For thumb/arch=armv7ve+nofp/cpu=cortex-a7/float-abi=soft/fpu=auto:

```text
FAIL: gcc.dg/fold-copysign-1.c scan-tree-dump-times cddce1 "= -" 1
FAIL: gcc.dg/fold-copysign-1.c scan-tree-dump-times cddce1 "= ABS_EXPR" 2
FAIL: gcc.dg/pr55152-2.c scan-tree-dump-times optimized "ABS_EXPR" 2
FAIL: gcc.dg/tree-ssa/abs-4.c scan-tree-dump-times optimized "= ABS_EXPR" 3
FAIL: gcc.dg/tree-ssa/abs-4.c scan-tree-dump-times optimized "= -" 3
FAIL: gcc.dg/tree-ssa/abs-5.c scan-tree-dump-times optimized "= ABS_EXPR" 6
FAIL: gcc.dg/tree-ssa/backprop-6.c scan-tree-dump-times backprop 
"Deleting[^\\n]* = -" 6
FAIL: gcc.dg/tree-ssa/backprop-6.c scan-tree-dump-times backprop 
"Deleting[^\\n]* = ABS_EXPR <" 3
FAIL: gcc.dg/tree-ssa/copy-sign-2.c scan-tree-dump-times optimized "ABS" 2
```

For thumb/arch=armv7ve+simd/cpu=cortex-a7/float-abi=hard/fpu=auto:

```text
FAIL: gcc.dg/fold-copysign-1.c scan-tree-dump-times cddce1 "__builtin_copysign" 
1
FAIL: gcc.dg/fold-copysign-1.c scan-tree-dump-times cddce1 "= ABS_EXPR" 1
FAIL: gcc.dg/pr55152-2.c scan-tree-dump-times optimized ".COPYSIGN" 1
FAIL: gcc.dg/pr55152-2.c scan-tree-dump-times optimized "ABS_EXPR" 1
FAIL: gcc.dg/tree-ssa/abs-4.c scan-tree-dump-times optimized "= ABS_EXPR" 1
FAIL: gcc.dg/tree-ssa/abs-4.c scan-tree-dump-times optimized "= -" 1
FAIL: gcc.dg/tree-ssa/abs-4.c scan-tree-dump-times optimized "= .COPYSIGN" 2
FAIL: gcc.dg/tree-ssa/abs-5.c scan-tree-dump-times optimized "= ABS_EXPR" 4
FAIL: gcc.dg/tree-ssa/abs-5.c scan-tree-dump-times optimized "= \\.COPYSIGN" 2
FAIL: gcc.dg/tree-ssa/backprop-6.c scan-tree-dump-times backprop 
"Deleting[^\\n]* = -" 4
FAIL: gcc.dg/tree-ssa/backprop-6.c scan-tree-dump-times backprop 
"Deleting[^\\n]* = \\.COPYSIGN" 2
FAIL: gcc.dg/tree-ssa/backprop-6.c scan-tree-dump-times backprop 
"Deleting[^\\n]* = ABS_EXPR <" 1
FAIL: gcc.dg/tree-ssa/copy-sign-2.c scan-tree-dump-times optimized "ABS" 1
FAIL: gcc.dg/tree-ssa/copy-sign-2.c scan-tree-dump-times optimized ".COPYSIGN" 1
FAIL: gcc.dg/tree-ssa/copysign-signbit.c scan-tree-dump-times optimized " = 
\\.COPYSIGN " 6
FAIL: gcc.dg/tree-ssa/copysign-signbit.c scan-tree-dump-not optimized "signbit"
FAIL: gcc.dg/tree-ssa/pr109843.c scan-tree-dump-not optimized "signbit"
FAIL: gcc.dg/tree-ssa/pr109843.c scan-tree-dump-times optimized "= \\.COPYSIGN" 
9
FAIL: gcc.dg/tree-ssa/pr109843.c scan-tree-dump-times optimized " = -" 4
FAIL: gcc.dg/tree-ssa/pr112472.c scan-tree-dump-not optimized " double "
FAIL: gcc.dg/tree-ssa/pr112472.c scan-tree-dump-times optimized ".COPYSIGN" 1
FAIL: gcc.dg/tree-ssa/pr112472.c scan-tree-dump-times optimized "-1.0e\\+0" 1
FAIL: gcc.dg/tree-ssa/pr112472.c scan-tree-dump-times optimized " ABS_EXPR " 1
```

There are similar failures for Cortex-M. These failures no longer appear with 
the two patches applied.


A nice side effect is that some functions now produce much less code.
For example, copysign1 in gcc.dg/tree-ssa/pr109843.c, compiled with -O2 
-march=armv7-a+fp -mfloat-abi=hard -marm, becomes:
```asm
copysign1:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        vmov    r3, s0  @ int
        vabs.f32        s0, s1
        cmp     r3, #0
        vneglt.f32      s0, s0
        bx      lr
```

With r17-5743-ge33129b871c302 it's instead:
```asm
copysign1:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        vmov    r3, s0  @ int
        vmov    r2, s1  @ int
        mvn     r3, r3
        mvn     r2, r2
        lsr     r3, r3, #31
        lsr     r2, r2, #31
        cmp     r3, r2
        vnegne.f32      s0, s1
        vmoveq.f32      s0, s1
        bx      lr
```

--
https://forge.sourceware.org/gcc/gcc/pulls/262#issuecomment-8082

Reply via email to