public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/64946] New: For Aarch64,  vectorization with "abs" instruction is not hapenning with vector elements of char/short type.
@ 2015-02-05 13:05 vekumar at gcc dot gnu.org
  2015-02-05 13:13 ` [Bug tree-optimization/64946] " vekumar at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-02-05 13:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

            Bug ID: 64946
           Summary: For Aarch64,  vectorization with "abs" instruction is
                    not hapenning with vector elements of char/short type.
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vekumar at gcc dot gnu.org

For the below test case.

signed char a[100],b[100];
void absolute_s8 (void)
{
         int i;
         for (i=0; i<16; i++)
         a[i] = (b[i] > 0 ? b[i] : -b[i]);
};

gcc version 5.0.0 20150203 (experimental) (GCC) with  -O3 -S on
aarch64-none-linux-gnu generates the following assembly 

absolute_s8:
        adrp    x1, b
        adrp    x0, a
        add     x1, x1, :lo12:b
        add     x0, x0, :lo12:a
        ldr     q0, [x1]          <== loads vector of 16 char elements
        sshll   v1.8h, v0.8b, 0   <== 
        sshll2  v0.8h, v0.16b, 0  <==
        sshll   v3.4s, v1.4h, 0   <==
        sshll   v2.4s, v0.4h, 0   <==
        sshll2  v1.4s, v1.8h, 0   <==
        sshll2  v0.4s, v0.8h, 0   <== promotes every element to "int"
        abs     v3.4s, v3.4s      <== Performs abs as vector of ints. 
        abs     v2.4s, v2.4s
        abs     v1.4s, v1.4s
        abs     v0.4s, v0.4s
        xtn     v4.4h, v3.4s
        xtn2    v4.8h, v1.4s
        xtn     v1.4h, v2.4s
        xtn2    v1.8h, v0.4s
        xtn     v0.8b, v4.8h
        xtn2    v0.16b, v1.8h
        str     q0, [x0]
        ret

Vectorization is done in INT or SI mode although Aarch64 supports abs v0.16b
v0.16b.

Expected code 

absolute_s8:
        adrp    x1, b
        adrp    x0, a
        add     x1, x1, :lo12:b
        add     x0, x0, :lo12:a
        ldr     q0, [x1]          <== loads vector of 16 char elements
        abs     v0.16b, v0.16b    <== abs in vector of chars
        str     q0, [x0]
        ret


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] For Aarch64,  vectorization with "abs" instruction is not hapenning with vector elements of char/short type.
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
@ 2015-02-05 13:13 ` vekumar at gcc dot gnu.org
  2015-02-05 14:00 ` [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types jgreenhalgh at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-02-05 13:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #1 from vekumar at gcc dot gnu.org ---
The test case is got from gcc.target/aarch64/vect-abs-compile.c


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
  2015-02-05 13:13 ` [Bug tree-optimization/64946] " vekumar at gcc dot gnu.org
@ 2015-02-05 14:00 ` jgreenhalgh at gcc dot gnu.org
  2015-02-26  8:48 ` vekumar at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jgreenhalgh at gcc dot gnu.org @ 2015-02-05 14:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

James Greenhalgh <jgreenhalgh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|aarch64                     |aarch64*-none-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-05
                 CC|                            |jgreenhalgh at gcc dot gnu.org
            Summary|For Aarch64,  vectorization |[AArch64]
                   |with "abs" instruction is   |gcc.target/aarch64/vect-abs
                   |not hapenning with vector   |-compile.c - "abs"
                   |elements of char/short      |vectorization fails for
                   |type.                       |char/short types
     Ever confirmed|0                           |1
      Known to fail|                            |4.8.0

--- Comment #2 from James Greenhalgh <jgreenhalgh at gcc dot gnu.org> ---
This has been failing since the first GCC versions supporting AArch64.
Confirmed and bug updated.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
  2015-02-05 13:13 ` [Bug tree-optimization/64946] " vekumar at gcc dot gnu.org
  2015-02-05 14:00 ` [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types jgreenhalgh at gcc dot gnu.org
@ 2015-02-26  8:48 ` vekumar at gcc dot gnu.org
  2015-02-26  9:09 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-02-26  8:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

vekumar at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #3 from vekumar at gcc dot gnu.org ---
Richard, 

As per your suggestion, adding a pattern for type demotion in match.pd solves
this.

(simplify
 ( convert (abs (convert@1 @0)))
 ( if (INTEGRAL_TYPE_P (type)
      /* We check for type compatibility between @0 and @1 below,
         so there's no need to check that @1/@3 are integral types.  */
      && INTEGRAL_TYPE_P (TREE_TYPE (@0))
      && INTEGRAL_TYPE_P (TREE_TYPE (@1))
      /* The precision of the type of each operand must match the
         precision of the mode of each operand, similarly for the
         result.  */
      && (TYPE_PRECISION (TREE_TYPE (@0))
          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
      && (TYPE_PRECISION (TREE_TYPE (@1))
          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
      && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
      /* The inner conversion must be a widening conversion.  */
      && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))
      && ((GENERIC
           && (TYPE_MAIN_VARIANT (TREE_TYPE (@0))
               == TYPE_MAIN_VARIANT (type)))
          || (GIMPLE
              && types_compatible_p (TREE_TYPE (@0), type))))
   (abs @0)))


I have not yet tested it. Will it have implication on targets that does not
support vectorization with short/char types?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2015-02-26  8:48 ` vekumar at gcc dot gnu.org
@ 2015-02-26  9:09 ` pinskia at gcc dot gnu.org
  2015-02-26  9:32 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-02-26  9:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is really a duplicate of bug 22199.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2015-02-26  9:09 ` pinskia at gcc dot gnu.org
@ 2015-02-26  9:32 ` pinskia at gcc dot gnu.org
  2015-02-26  9:43 ` vekumar at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-02-26  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you should always use an unsigned type here so it will be defined in
the IR.  This is mentioned in bug 22199#c3 .


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2015-02-26  9:32 ` pinskia at gcc dot gnu.org
@ 2015-02-26  9:43 ` vekumar at gcc dot gnu.org
  2015-02-26  9:56 ` rguenther at suse dot de
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-02-26  9:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #6 from vekumar at gcc dot gnu.org ---
(In reply to Andrew Pinski from comment #5)
> I think you should always use an unsigned type here so it will be defined in
> the IR.  This is mentioned in bug 22199#c3 .

Andrew I missed to include something like this 

+      (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+       (convert (op @0 @1)))

as in  https://gcc.gnu.org/viewcvs?rev=220695&root=gcc&view=rev


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2015-02-26  9:43 ` vekumar at gcc dot gnu.org
@ 2015-02-26  9:56 ` rguenther at suse dot de
  2015-02-26 10:07 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenther at suse dot de @ 2015-02-26  9:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #7 from rguenther at suse dot de <rguenther at suse dot de> ---
On Thu, 26 Feb 2015, vekumar at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946
> 
> vekumar at gcc dot gnu.org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |rguenth at gcc dot gnu.org
> 
> --- Comment #3 from vekumar at gcc dot gnu.org ---
> Richard, 
> 
> As per your suggestion, adding a pattern for type demotion in match.pd solves
> this.
> 
> (simplify
>  ( convert (abs (convert@1 @0)))
>  ( if (INTEGRAL_TYPE_P (type)
>       /* We check for type compatibility between @0 and @1 below,
>          so there's no need to check that @1/@3 are integral types.  */
>       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
>       && INTEGRAL_TYPE_P (TREE_TYPE (@1))
>       /* The precision of the type of each operand must match the
>          precision of the mode of each operand, similarly for the
>          result.  */
>       && (TYPE_PRECISION (TREE_TYPE (@0))
>           == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
>       && (TYPE_PRECISION (TREE_TYPE (@1))
>           == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
>       && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
>       /* The inner conversion must be a widening conversion.  */
>       && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))
>       && ((GENERIC
>            && (TYPE_MAIN_VARIANT (TREE_TYPE (@0))
>                == TYPE_MAIN_VARIANT (type)))
>           || (GIMPLE
>               && types_compatible_p (TREE_TYPE (@0), type))))
>    (abs @0)))
> 
> 
> I have not yet tested it. Will it have implication on targets that does not
> support vectorization with short/char types?

I don't see how it could.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2015-02-26  9:56 ` rguenther at suse dot de
@ 2015-02-26 10:07 ` pinskia at gcc dot gnu.org
  2015-02-26 16:42 ` vekumar at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-02-26 10:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to vekumar from comment #6)
> (In reply to Andrew Pinski from comment #5)
> > I think you should always use an unsigned type here so it will be defined in
> > the IR.  This is mentioned in bug 22199#c3 .
> 
> Andrew I missed to include something like this 
> 
> +      (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
> +       (convert (op @0 @1)))
> 
> as in  https://gcc.gnu.org/viewcvs?rev=220695&root=gcc&view=rev

I did not miss that, I am just saying you should do it for types that have
undefined overflow also but convert it into a type that wraps.  Meaning you are
not apply the full optimization really.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2015-02-26 10:07 ` pinskia at gcc dot gnu.org
@ 2015-02-26 16:42 ` vekumar at gcc dot gnu.org
  2015-05-15 14:37 ` ramana at gcc dot gnu.org
  2021-06-03  3:35 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: vekumar at gcc dot gnu.org @ 2015-02-26 16:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

--- Comment #9 from vekumar at gcc dot gnu.org ---
This match.pd pattern vectorizes the PR but works only with -fwrapv.

(simplify
 ( convert (abs (convert@1 @0)))
 ( if (INTEGRAL_TYPE_P (type)
      /* We check for type compatibility between @0 and @1 below,
         so there's no need to check that @1/@3 are integral types.  */
      && INTEGRAL_TYPE_P (TREE_TYPE (@0))
      && INTEGRAL_TYPE_P (TREE_TYPE (@1))
      /* The precision of the type of each operand must match the
         precision of the mode of each operand, similarly for the
         result.  */
      && (TYPE_PRECISION (TREE_TYPE (@0))
          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
      && (TYPE_PRECISION (TREE_TYPE (@1))
          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
      && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
      /* The inner conversion must be a widening conversion.  */
      && TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))
      && ((GENERIC
           && (TYPE_MAIN_VARIANT (TREE_TYPE (@0))
               == TYPE_MAIN_VARIANT (type)))
          || (GIMPLE
              && types_compatible_p (TREE_TYPE (@0), type))))
   (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
    (abs @0))))

For default cases (when no -fwrapv is given), doing ABSE_EXPR(shorttype) will
invoke undefined behaviour when value is -32678. similarly for signed char min.

As per Richard suggestion we need to move to a new tree code ABSU_EXPR to do
this type of folding optimization.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2015-02-26 16:42 ` vekumar at gcc dot gnu.org
@ 2015-05-15 14:37 ` ramana at gcc dot gnu.org
  2021-06-03  3:35 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: ramana at gcc dot gnu.org @ 2015-05-15 14:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |ramana at gcc dot gnu.org

--- Comment #10 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> ---
assigned to Venkat.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types
  2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2015-05-15 14:37 ` ramana at gcc dot gnu.org
@ 2021-06-03  3:35 ` pinskia at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-03  3:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64946
Bug 64946 depends on bug 22199, which changed state.

Bug 22199 Summary: fold does not optimize (int)ABS_EXPR<(long long)(int_var)>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22199

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-06-03  3:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05 13:05 [Bug tree-optimization/64946] New: For Aarch64, vectorization with "abs" instruction is not hapenning with vector elements of char/short type vekumar at gcc dot gnu.org
2015-02-05 13:13 ` [Bug tree-optimization/64946] " vekumar at gcc dot gnu.org
2015-02-05 14:00 ` [Bug tree-optimization/64946] [AArch64] gcc.target/aarch64/vect-abs-compile.c - "abs" vectorization fails for char/short types jgreenhalgh at gcc dot gnu.org
2015-02-26  8:48 ` vekumar at gcc dot gnu.org
2015-02-26  9:09 ` pinskia at gcc dot gnu.org
2015-02-26  9:32 ` pinskia at gcc dot gnu.org
2015-02-26  9:43 ` vekumar at gcc dot gnu.org
2015-02-26  9:56 ` rguenther at suse dot de
2015-02-26 10:07 ` pinskia at gcc dot gnu.org
2015-02-26 16:42 ` vekumar at gcc dot gnu.org
2015-05-15 14:37 ` ramana at gcc dot gnu.org
2021-06-03  3:35 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).