public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "danglin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102162] New: Byte-wise access optimized away at -O1 and above
Date: Wed, 01 Sep 2021 16:52:51 +0000	[thread overview]
Message-ID: <bug-102162-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 102162
           Summary: Byte-wise access optimized away at -O1 and above
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danglin at gcc dot gnu.org
                CC: helge.deller at sap dot com
  Target Milestone: ---
              Host: hppa*-*-linux*
            Target: hppa*-*-linux*
             Build: hppa*-*-linux*

Created attachment 51394
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51394&action=edit
Test case

The packed attribute is used in Linux v5.14 to request byte-wise access
to unaligned data.  This is important on hppa as loads and stores require
strict alignment.

The attached test program is miscompiled at -O1 and above.  The byte-wise
accesses are optimized to a single ldw instruction during RTL expansion:

        .LEVEL 2.0w
        .text
        .align 8
.globl test
        .type   test, @function
test:
        .PROC
        .CALLINFO FRAME=0,NO_CALLS
        .ENTRY
        addil LT'output_len,%r27
        ldd RT'output_len(%r1),%r28
        ldw 0(%r28),%r28
        bve (%r2)
        extrd,s %r28,63,32,%r28
        .EXIT
        .PROCEND
        .size   test, .-test
.globl output_len
        .section        .bss
        .type   output_len, @object
        .size   output_len, 4
        .align 1
output_len:
        .block 4
        .ident  "GCC: (GNU) 10.3.0"

This faults when output_len is not aligned on a word boundary.

Not sure, but problem may be the test-unaligned.c.027t.einline pass:

;; Function get_unaligned_le32 (get_unaligned_le32, funcdef_no=0,
decl_uid=1506, cgraph_uid=1, symbol_order=1)

Iterations: 0
get_unaligned_le32 (const void * p)
{
  const struct
  {
    u32 x;
  } * __pptr;
  u32 _4;

  <bb 2> :
  __pptr_2 = p_1(D);
  _4 = __pptr_2->x;
  return _4;

}



;; Function test (test, funcdef_no=1, decl_uid=1512, cgraph_uid=2,
symbol_order=2)

Iterations: 1

Symbols to be put in SSA form
{ D.1520 D.1524 }
Incremental SSA update started at block: 0
Number of blocks in CFG: 5
Number of blocks to update: 4 ( 80%)


Merging blocks 2 and 4
Merging blocks 2 and 3
test ()
{
  u32 D.1524;
  unsigned int _1;
  unsigned int _3;
  int _4;

  <bb 2> :
  _3 = MEM[(const struct  *)&output_len].x;
  _5 = _3;
  _1 = _5;
  _4 = (int) _1;
  return _4;

}

Ultimately, the MEM gets expanded to the ldw.

             reply	other threads:[~2021-09-01 16:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 16:52 danglin at gcc dot gnu.org [this message]
2021-09-01 18:52 ` [Bug tree-optimization/102162] " danglin at gcc dot gnu.org
2021-09-01 20:14 ` arnd at linaro dot org
2021-09-01 20:52 ` deller at gmx dot de
2021-09-01 20:56 ` dave.anglin at bell dot net
2021-09-01 21:08 ` dave.anglin at bell dot net
2021-09-01 21:15 ` deller at gmx dot de
2021-09-01 21:19 ` dave.anglin at bell dot net
2021-09-01 21:25 ` deller at gmx dot de
2021-09-01 21:29 ` deller at gmx dot de
2021-09-01 21:48 ` pinskia at gcc dot gnu.org
2021-09-01 21:51 ` [Bug middle-end/102162] " pinskia at gcc dot gnu.org
2021-09-01 21:52 ` pinskia at gcc dot gnu.org
2021-09-01 22:35 ` dave.anglin at bell dot net
2021-09-01 22:46 ` dave.anglin at bell dot net
2021-09-01 22:56 ` pinskia at gcc dot gnu.org
2021-09-01 23:19 ` pinskia at gcc dot gnu.org
2021-09-01 23:21 ` pinskia at gcc dot gnu.org
2021-09-01 23:29 ` pinskia at gcc dot gnu.org
2021-09-01 23:45 ` pinskia at gcc dot gnu.org
2021-09-01 23:55 ` pinskia at gcc dot gnu.org
2021-09-02  0:02 ` dave.anglin at bell dot net
2021-09-02  0:19 ` pinskia at gcc dot gnu.org
2021-09-02  0:23 ` pinskia at gcc dot gnu.org
2021-09-02  0:47 ` dave.anglin at bell dot net
2021-09-02  0:49 ` pinskia at gcc dot gnu.org
2021-09-02  3:33 ` pinskia at gcc dot gnu.org
2021-09-02  7:12 ` rguenth at gcc dot gnu.org
2021-09-02  9:01 ` arnd at linaro dot org
2021-09-02  9:41 ` deller at gmx dot de
2021-09-02  9:52 ` pinskia at gcc dot gnu.org
2021-09-02 13:59 ` deller at gmx dot de
2021-09-02 14:00 ` deller at gmx dot de
2021-09-03 23:25 ` deller at gmx dot de

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-102162-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).