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

Reply via email to