public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved
@ 2023-08-12  9:37 pinskia at gcc dot gnu.org
  2023-08-12  9:42 ` [Bug tree-optimization/111002] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-12  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111002
           Summary: Code generation for vectorized -(a[i] != 0) with
                    number of elements chang could be improved
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: pinskia at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Testcase:
```
void __attribute__ ((noipa))
f (int *__restrict r,
   int *__restrict a,
   short *__restrict pred)
{
  for (int i = 0; i < 1024; ++i)
    r[i] = pred[i] != 0 ? -1 : 0;
}
```

Kinda of patch:
```
/* Sink unary operations to branches, but only if we do fold both.  */
(for op (negate bit_not abs absu)
 (simplify
  (op (view_convert? (vec_cond:s @0 @1 @2)))
  (if (element_precision (type) == element_precision (@1))
   (vec_cond @0 (op! (view_convert @1)) (op! (view_convert @2))))))
```

That is `Sink unary operations` one needs to add support for view_convert there
...

I Noticed this while working on PR 110986 (but is not needed for that issue).

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

* [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved
  2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
@ 2023-08-12  9:42 ` pinskia at gcc dot gnu.org
  2023-08-21  0:06 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-12  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-08-12
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note it looks like 4.7 used to produce the code without the secondary negate
there ...

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

* [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved
  2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
  2023-08-12  9:42 ` [Bug tree-optimization/111002] " pinskia at gcc dot gnu.org
@ 2023-08-21  0:06 ` pinskia at gcc dot gnu.org
  2023-08-21  3:22 ` [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change " pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21  0:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
here is the corrected patch:
diff --git a/gcc/match.pd b/gcc/match.pd
index 851f1af6eac..81666f28465 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4718,6 +4718,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       && types_match (TREE_TYPE (@0), truth_type_for (type)))
   (vec_cond @0 (convert! @1) (convert! @2))))

+/* Likewise for view_convert of nop_conversions. */
+(simplify
+ (view_convert (vec_cond:s @0 @1 @2))
+ (if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@1))
+      && known_eq (TYPE_VECTOR_SUBPARTS (type),
+                  TYPE_VECTOR_SUBPARTS (TREE_TYPE (@1)))
+      && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@1))))
+  (vec_cond @0 (view_convert! @1) (view_convert! @2))))
+
 /* Sink binary operation to branches, but only if we can fold it.  */
 (for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
         lshift rshift rdiv trunc_div ceil_div floor_div round_div

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

* [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change could be improved
  2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
  2023-08-12  9:42 ` [Bug tree-optimization/111002] " pinskia at gcc dot gnu.org
  2023-08-21  0:06 ` pinskia at gcc dot gnu.org
@ 2023-08-21  3:22 ` pinskia at gcc dot gnu.org
  2023-08-21  7:45 ` cvs-commit at gcc dot gnu.org
  2023-08-21  7:47 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21  3:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-August/
                   |                            |627955.html

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/627955.html

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

* [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change could be improved
  2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-21  3:22 ` [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change " pinskia at gcc dot gnu.org
@ 2023-08-21  7:45 ` cvs-commit at gcc dot gnu.org
  2023-08-21  7:47 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-21  7:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:47b833a9abe19d862a773d20dd6f961dcf811a11

commit r14-3350-g47b833a9abe19d862a773d20dd6f961dcf811a11
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sun Aug 20 17:22:27 2023 -0700

    MATCH: [PR111002] Sink view_convert for vec_cond

    Like convert we can sink view_convert into vec_cond but
    we can only do it if the element types are nop_conversions.
    This is to allow conversion between signed and unsigned types only.
    Rather than between integer and float types which mess up the vec_cond
    so that isel does not understand `a?-1:0` is still that.

    OK? Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu.

            PR tree-optimization/111002

    gcc/ChangeLog:

            * match.pd (view_convert(vec_cond(a,b,c))): New pattern.

    gcc/testsuite/ChangeLog:

            * gcc.target/aarch64/sve/cond_convert_8.c: New test.

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

* [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change could be improved
  2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-08-21  7:45 ` cvs-commit at gcc dot gnu.org
@ 2023-08-21  7:47 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-08-21  7:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-12  9:37 [Bug tree-optimization/111002] New: Code generation for vectorized -(a[i] != 0) with number of elements chang could be improved pinskia at gcc dot gnu.org
2023-08-12  9:42 ` [Bug tree-optimization/111002] " pinskia at gcc dot gnu.org
2023-08-21  0:06 ` pinskia at gcc dot gnu.org
2023-08-21  3:22 ` [Bug tree-optimization/111002] Code generation for vectorized -(a[i] != 0) with number of elements change " pinskia at gcc dot gnu.org
2023-08-21  7:45 ` cvs-commit at gcc dot gnu.org
2023-08-21  7:47 ` 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).