[Bug target/68543] New: Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] New: Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

            Bug ID: 68543
           Summary: Implement overflow arithmetic standard names
                    {u,}{add,sub,mul}v4<mode> and/or negv3<mode>
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66112#c13
we should consider implementing the various overflow arithmetic standard name
expanders that take a label argument and emit a jump to it if the operation
overflows.

A motivational example is the code quality regression from PR 68381:
int
foo(unsigned short x, unsigned short y)
{
  int r;
  if (__builtin_mul_overflow (x, y, &r))
    __builtin_abort ();
  return r;
}

which for aarch64 at -O3 generates:
foo:
        uxth    w0, w0
        uxth    w1, w1
        umull   x0, w0, w1
        tbnz    w0, #31, .L6
        mov     w2, 0
        cbnz    w2, .L6
        ret
.L6:
        stp     x29, x30, [sp, -16]!
        add     x29, sp, 0
        bl      abort

which could be improved
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

--- Comment #1 from ktkachov at gcc dot gnu.org ---
Maybe we can avoid defining custom expanders if we define
WORD_REGISTER_OPERATIONS for aarch64.
It's defined for arm and the documentation hints that it should be true for
most RISC targets.

Then the default fallback codegen for the given example is much improved:
foo:
        uxth    x0, w0
        uxth    x1, w1
        mul     x0, x0, x1
        cmp     x0, x0, sxtw
        bne     .L10
        ret
.L10:
        stp     x29, x30, [sp, -16]!
        add     x29, sp, 0
        bl      abort


However, we need to investigate the other codegen effects that come with
WORD_REGISTER_OPERATIONS, in particular to make sure that the aarch64 patterns
cope with the slightly different strategies of using subregs and sign/zero
extends in combine
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

--- Comment #2 from Michael Collison <michael.collison at linaro dot org> ---
Great idea I will look into this.

On 12/10/2015 4:02 AM, ktkachov at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543
>
> --- Comment #1 from ktkachov at gcc dot gnu.org ---
> Maybe we can avoid defining custom expanders if we define
> WORD_REGISTER_OPERATIONS for aarch64.
> It's defined for arm and the documentation hints that it should be true for
> most RISC targets.
>
> Then the default fallback codegen for the given example is much improved:
> foo:
>          uxth    x0, w0
>          uxth    x1, w1
>          mul     x0, x0, x1
>          cmp     x0, x0, sxtw
>          bne     .L10
>          ret
> .L10:
>          stp     x29, x30, [sp, -16]!
>          add     x29, sp, 0
>          bl      abort
>
>
> However, we need to investigate the other codegen effects that come with
> WORD_REGISTER_OPERATIONS, in particular to make sure that the aarch64 patterns
> cope with the slightly different strategies of using subregs and sign/zero
> extends in combine
>
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

--- Comment #3 from ktkachov at gcc dot gnu.org ---
After some discussion on IRC, WORD_REGISTER_OPERATIONS seems wrong for aarch64
since 32-bit operations i.e. in SImode operate like normal 32-bit operations
because they use the 32-bit W-form of the registers. Thus they don't behave
like word_mode operations, because word_mode is DImode on aarch64.
So we may want to look at implementing the standard names after all
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

--- Comment #4 from Michael Collison <michael.collison at linaro dot org> ---
Okay thanks. After looking into the topic I did not see the direct
connection either.

On 12/11/2015 7:21 AM, ktkachov at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543
>
> --- Comment #3 from ktkachov at gcc dot gnu.org ---
> After some discussion on IRC, WORD_REGISTER_OPERATIONS seems wrong for aarch64
> since 32-bit operations i.e. in SImode operate like normal 32-bit operations
> because they use the 32-bit W-form of the registers. Thus they don't behave
> like word_mode operations, because word_mode is DImode on aarch64.
> So we may want to look at implementing the standard names after all
>
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-01-28
                 CC|                            |rth at gcc dot gnu.org
   Target Milestone|---                         |7.0
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #5 from Richard Henderson <rth at gcc dot gnu.org> ---
Confirmed.

Note that negv<mode>3 isn't required if subv<mode>4 accepts zero as
its first argument.

I don't believe that there is anything that aarch64 can usefully do
with mulv<mode>4 -- generic code should use the widening multiplies
as efficiently as anything we can do.

Patch for some of this at

  https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01903.html
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.0                         |7.2

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 7.1 has been released.
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.2                         |7.3

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.2 is being released, adjusting target milestone.
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.2                         |7.3
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.3                         |7.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 7.3 is being released, adjusting target milestone.
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.4                         |7.5
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|7.5                         |---
Reply | Threaded
Open this post in threaded view
|

[Bug target/68543] [AArch64] Implement overflow arithmetic standard names {u,}{add,sub,mul}v4<mode> and/or negv3<mode>

thiago at kde dot org
In reply to this post by thiago at kde dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68543

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |9.0

--- Comment #8 from Richard Henderson <rth at gcc dot gnu.org> ---
This feature was added in r262890, included in gcc 9.