public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manolis.tsamis at vrull dot eu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/106346] New: Potential regression on vectorization of left shift with constants
Date: Mon, 18 Jul 2022 18:28:10 +0000	[thread overview]
Message-ID: <bug-106346-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 106346
           Summary: Potential regression on vectorization of left shift
                    with constants
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manolis.tsamis at vrull dot eu
  Target Milestone: ---
            Target: aarch64

Created attachment 53317
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53317&action=edit
Does not vectorize on GCC > 10.3

The following test case:

  void foo (uint32_t dst[8], uint8_t src1[8], uint8_t src2[8])
  {
    uint16_t diff_e0 = src1[0] - src2[0];
    uint16_t diff_e1 = src1[1] - src2[1];
    uint16_t diff_e2 = src1[2] - src2[2];
    uint16_t diff_e3 = src1[3] - src2[3];
    uint16_t diff_e4 = src1[4] - src2[4];
    uint16_t diff_e5 = src1[5] - src2[5];
    uint16_t diff_e6 = src1[6] - src2[6];
    uint16_t diff_e7 = src1[7] - src2[7];

    uint32_t a0 = diff_e0 << 1;
    uint32_t a1 = diff_e1 << 3;
    uint32_t a2 = diff_e2 << 4;
    uint32_t a3 = diff_e3 << 2;
    uint32_t a4 = diff_e4 << 12;
    uint32_t a5 = diff_e5 << 11;
    uint32_t a6 = diff_e6 << 9;
    uint32_t a7 = diff_e7 << 3;

    dst[0] = a0;
    dst[1] = a1;
    dst[2] = a2;
    dst[3] = a3;
    dst[4] = a4;
    dst[5] = a5;
    dst[6] = a6;
    dst[7] = a7;
  }

Compiles at -O3 to nice vectorized code by loading the constants from memory in
GCC 10.3:

  ldr     d0, [x1]
  adrp    x3, .LC0
  ldr     d1, [x2]
  adrp    x1, .LC1
  ldr     q3, [x3, #:lo12:.LC0]
  usubl   v0.8h, v0.8b, v1.8b
  ldr     q2, [x1, #:lo12:.LC1]
  uxtl    v1.4s, v0.4h
  uxtl2   v0.4s, v0.8h
  sshl    v1.4s, v1.4s, v3.4s
  sshl    v0.4s, v0.4s, v2.4s
  stp     q1, q0, [x0]
  ret

But this has regressed in later releases, with GCC still loading the constants
from memory but also emitting a lot of scalar code before that. For example GCC
13 produces:

  adrp    x3, .LC0
  ldrb    w6, [x1, 4]
  fmov    d0, x6
  ldrb    w7, [x1]
  ldr     q5, [x3, #:lo12:.LC0]
  fmov    d1, x7
  ldrb    w3, [x1, 5]
  ldrb    w4, [x1, 1]
  ldrb    w8, [x2, 4]
  ldrb    w5, [x2, 5]
  ins     v0.h[1], w3
  ldrb    w6, [x2]
  fmov    d2, x8
  ldrb    w3, [x2, 1]
  fmov    d3, x6
  ins     v2.h[1], w5
  ins     v1.h[1], w4
  ldrb    w9, [x1, 2]
  ins     v3.h[1], w3
  ldrb    w8, [x1, 6]
  ldrb    w7, [x2, 2]
  ldrb    w6, [x2, 6]
  ins     v1.h[2], w9
  ins     v0.h[2], w8
  ldrb    w5, [x1, 3]
  ins     v3.h[2], w7
  ldrb    w4, [x1, 7]
  ins     v2.h[2], w6
  ldrb    w1, [x2, 7]
  ldrb    w3, [x2, 3]
  ins     v1.h[3], w5
  ins     v0.h[3], w4
  ins     v2.h[3], w1
  ins     v3.h[3], w3
  adrp    x1, .LC1
  ldr     q4, [x1, #:lo12:.LC1]
  sub     v1.4h, v1.4h, v3.4h
  sub     v0.4h, v0.4h, v2.4h
  uxtl    v1.4s, v1.4h
  uxtl    v0.4s, v0.4h
  sshl    v1.4s, v1.4s, v5.4s
  sshl    v0.4s, v0.4s, v4.4s
  stp     q1, q0, [x0]
  ret

Interestingly, this happens only with left shift and not with right shift.

GCC 10.3 vs trunk comparison: https://godbolt.org/z/xWbfGdfen

             reply	other threads:[~2022-07-18 18:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 18:28 manolis.tsamis at vrull dot eu [this message]
2022-07-19  6:52 ` [Bug target/106346] " rguenth at gcc dot gnu.org
2022-07-19 13:09 ` manolis.tsamis at vrull dot eu
2022-07-22 10:11 ` [Bug target/106346] Potential regression on vectorization of left shift with constants since r11-5160-g9fc9573f9a5e94 marxin at gcc dot gnu.org
2022-07-22 11:00 ` tnfchris at gcc dot gnu.org
2022-07-27  7:27 ` [Bug target/106346] [11/12/13 Regression] " tnfchris at gcc dot gnu.org
2022-07-27  7:48 ` rguenth at gcc dot gnu.org
2022-07-27  8:26 ` tnfchris at gcc dot gnu.org
2022-07-27  8:50 ` rguenther at suse dot de
2023-07-31 15:30 ` [Bug target/106346] [11/12/13/14 " tnfchris at gcc dot gnu.org
2023-08-04 12:50 ` cvs-commit at gcc dot gnu.org
2023-08-04 13:58 ` tnfchris 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-106346-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).