public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ktkachov at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/98581] New: unexpected reassociation for umin/umax ?
Date: Thu, 07 Jan 2021 12:52:05 +0000	[thread overview]
Message-ID: <bug-98581-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 98581
           Summary: unexpected reassociation for umin/umax ?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

typedef signed int *__restrict__ pSINT;
typedef unsigned int *__restrict__ pUINT;

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

void saba_s (pSINT a, pSINT b, pSINT c)
{
  int i;
  for (i = 0; i < 4; i++)
    c[i] += (MAX (a[i], b[i]) - MIN (a[i], b[i]));
}

void saba_u (pUINT a, pUINT b, pUINT c)
{
  int i;
  for (i = 0; i < 4; i++)
    c[i] += (MAX (a[i], b[i]) - MIN (a[i], b[i]));
}

On aarch64 at -O3 generates:
saba_s:
        ldr     q0, [x0]
        ldr     q1, [x1]
        ldr     q2, [x2]
        sabd    v0.4s, v0.4s, v1.4s
        add     v0.4s, v0.4s, v2.4s
        str     q0, [x2]
        ret

saba_u:
        ldr     q1, [x0]
        ldr     q2, [x1]
        ldr     q3, [x2]
        umax    v0.4s, v1.4s, v2.4s
        umin    v1.4s, v1.4s, v2.4s
        add     v0.4s, v0.4s, v3.4s
        sub     v0.4s, v0.4s, v1.4s
        str     q0, [x2]
        ret

I would expect the (MAX (a[i], b[i]) - MIN (a[i], b[i])) part to match a uabd
instruction for the unsigned case, but it looks like the add and sub operations
are swapped which prevents the RTL pattern matching the operation.
This comes out this way out of GIMPLE. At expand the signed version is:
  vect__4.6_40 = MEM <vector(4) int> [(int *)c_16(D)];
  vect__6.9_37 = MEM <vector(4) int> [(int *)b_17(D)];
  vect__8.12_34 = MEM <vector(4) int> [(int *)a_18(D)];
  vect__9.13_33 = MAX_EXPR <vect__8.12_34, vect__6.9_37>;
  vect__10.14_32 = MIN_EXPR <vect__8.12_34, vect__6.9_37>;
  vect__11.15_31 = vect__9.13_33 - vect__10.14_32;
  vect__12.16_30 = vect__11.15_31 + vect__4.6_40;
  MEM <vector(4) int> [(int *)c_16(D)] = vect__12.16_30;
  return;


the unsigned is:
  vect__4.25_38 = MEM <vector(4) unsigned int> [(unsigned int *)c_16(D)];
  vect__6.28_35 = MEM <vector(4) unsigned int> [(unsigned int *)b_17(D)];
  vect__8.31_32 = MEM <vector(4) unsigned int> [(unsigned int *)a_18(D)];
  vect__9.32_31 = MAX_EXPR <vect__8.31_32, vect__6.28_35>;
  vect__10.33_30 = MIN_EXPR <vect__8.31_32, vect__6.28_35>;
  vect__13.34_29 = vect__9.32_31 + vect__4.25_38;
  vect__12.35_28 = vect__13.34_29 - vect__10.33_30;
  MEM <vector(4) unsigned int> [(unsigned int *)c_16(D)] = vect__12.35_28;
  return;

             reply	other threads:[~2021-01-07 12:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-07 12:52 ktkachov at gcc dot gnu.org [this message]
2021-01-07 13:31 ` [Bug tree-optimization/98581] " rguenth at gcc dot gnu.org
2023-05-02  1:19 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98581-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).