public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109240] New: Missed fneg/fsub optimization
@ 2023-03-21 19:25 jakub at gcc dot gnu.org
  2023-03-22  7:43 ` [Bug tree-optimization/109240] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-21 19:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109240
           Summary: Missed fneg/fsub optimization
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: avieira at gcc dot gnu.org, burnus at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, marxin at gcc dot gnu.org,
                    tnfchris at gcc dot gnu.org
        Depends on: 109230
  Target Milestone: ---
              Host: aarch64-linux-gnu
            Target: aarch64-linux-gnu

+++ This bug was initially created as a clone of Bug #109230 +++

On aarch64 we optimize at -O2 only half of the following routines:
typedef float V __attribute__((vector_size (4 * sizeof (float))));
typedef int VI __attribute__((vector_size (4 * sizeof (float))));

__attribute__((noipa)) V
foo (V x, V y)
{
  V a = x - y;
  V b = y + x;
  return __builtin_shuffle (b, a, (VI) { 0, 5, 2, 7 });
}

__attribute__((noipa)) V
bar (V x, V y)
{
  V a = x - y;
  V b = y + x;
  return __builtin_shuffle (a, b, (VI) { 4, 1, 6, 3 });
}

__attribute__((noipa)) V
baz (V x, V y)
{
  V a = x - y;
  V b = y + x;
  return __builtin_shuffle (b, a, (VI) { 4, 1, 6, 3 });
}

__attribute__((noipa)) V
qux (V x, V y)
{
  V a = x - y;
  V b = y + x;
  return __builtin_shuffle (a, b, (VI) { 0, 5, 2, 7 });
}

__attribute__((noipa)) V
boo (V x, V y)
{
  V a = x + y;
  V b = y - x;
  return __builtin_shuffle (b, a, (VI) { 0, 5, 2, 7 });
}

__attribute__((noipa)) V
corge (V x, V y)
{
  V a = x + y;
  V b = y - x;
  return __builtin_shuffle (a, b, (VI) { 4, 1, 6, 3 });
}

__attribute__((noipa)) V
fred (V x, V y)
{
  V a = x + y;
  V b = y - x;
  return __builtin_shuffle (b, a, (VI) { 4, 1, 6, 3 });
}

__attribute__((noipa)) V
garply (V x, V y)
{
  V a = x + y;
  V b = y - x;
  return __builtin_shuffle (a, b, (VI) { 0, 5, 2, 7 });
}

starting with r13-4024-gb2bb611d90d01f64a24 (plus r13-4122-g1bc7efa948f751
bugfix).
The other half could be handled similarly, just with fneg+fsub rather than
fneg+fadd.

Unfortunately, match.pd canonicalizes those, we still have 0, 5, 2, 7
permutations for all of them, but the two operations swapped.  Unfortunately
match.pd doesn't allow :c
on vec_perm, and if we use (for op (plus minus)
                                otherop (minus plus)
then we couldn't add :c to the plus one.  So, copy and paste the whole large
simplification, swap (plus:c @0 @1) and (minus @0 @1) and replace (plus at the
end with (minus?  Or handle the commutativity manually?
(for op (plus minus)
     otherop (minus plus)
 (simplify
  (vec_perm (op @0 @1) (otherop @2 @3) VECTOR_CST@4)
and use operand_equal_p manually to allow all forms we want?


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109230
[Bug 109230] [13 Regression] Maybe wrong code for opus package on aarch64 since
r13-4122-g1bc7efa948f751

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

* [Bug tree-optimization/109240] Missed fneg/fsub optimization
  2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
@ 2023-03-22  7:43 ` rguenth at gcc dot gnu.org
  2023-03-22  9:39 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-22  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
You can try if match.pd is "preprocessed enough" to make use of macros.

vec_perm:c cannot be done, "selective" :c on a for iterator is also not
possible.  If you have an idea for a syntax to express the "iteration"
please share it.

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

* [Bug tree-optimization/109240] Missed fneg/fsub optimization
  2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
  2023-03-22  7:43 ` [Bug tree-optimization/109240] " rguenth at gcc dot gnu.org
@ 2023-03-22  9:39 ` jakub at gcc dot gnu.org
  2023-03-26 18:44 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-22  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-03-22
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 54728
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54728&action=edit
gcc13-pr109240.patch

Actually, I think using manual operand_equal_p isn't that bad.

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

* [Bug tree-optimization/109240] Missed fneg/fsub optimization
  2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
  2023-03-22  7:43 ` [Bug tree-optimization/109240] " rguenth at gcc dot gnu.org
  2023-03-22  9:39 ` jakub at gcc dot gnu.org
@ 2023-03-26 18:44 ` jakub at gcc dot gnu.org
  2023-04-18  9:02 ` cvs-commit at gcc dot gnu.org
  2023-04-18  9:03 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-26 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

Bug 109230 Summary: [13 Regression] Maybe wrong code for opus package on aarch64 since r13-4122-g1bc7efa948f751
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109230

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

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

* [Bug tree-optimization/109240] Missed fneg/fsub optimization
  2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-03-26 18:44 ` jakub at gcc dot gnu.org
@ 2023-04-18  9:02 ` cvs-commit at gcc dot gnu.org
  2023-04-18  9:03 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-18  9:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:2349e69125335d4c8c5e43cf3643844519d154c3

commit r14-22-g2349e69125335d4c8c5e43cf3643844519d154c3
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Apr 18 11:01:47 2023 +0200

    match.pd: Improve fneg/fadd optimization [PR109240]

    match.pd has mostly for AArch64 an optimization in which it optimizes
    certain forms of __builtin_shuffle of x + y and x - y vectors into
    fneg using twice as wide element type so that every other sign is changed,
    followed by fadd.

    The following patch extends that optimization, so that it can handle
    other forms as well, using the same fneg but fsub instead of fadd.

    As the plus is commutative and minus is not and I want to handle
    vec_perm with plus minus and minus plus order preferrably in one
    pattern, I had to do the matching operand checks by hand.

    2023-04-18  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/109240
            * match.pd (fneg/fadd): Rewrite such that it handles both plus as
            first vec_perm operand and minus as second using fneg/fadd and
            minus as first vec_perm operand and plus as second using fneg/fsub.

            * gcc.target/aarch64/simd/addsub_2.c: New test.
            * gcc.target/aarch64/sve/addsub_2.c: New test.

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

* [Bug tree-optimization/109240] Missed fneg/fsub optimization
  2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-04-18  9:02 ` cvs-commit at gcc dot gnu.org
@ 2023-04-18  9:03 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-18  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Implemented for GCC 14.

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

end of thread, other threads:[~2023-04-18  9:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 19:25 [Bug tree-optimization/109240] New: Missed fneg/fsub optimization jakub at gcc dot gnu.org
2023-03-22  7:43 ` [Bug tree-optimization/109240] " rguenth at gcc dot gnu.org
2023-03-22  9:39 ` jakub at gcc dot gnu.org
2023-03-26 18:44 ` jakub at gcc dot gnu.org
2023-04-18  9:02 ` cvs-commit at gcc dot gnu.org
2023-04-18  9:03 ` jakub 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).