public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zhenqiang.chen at linaro dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/53861] New: Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment
Date: Thu, 05 Jul 2012 08:32:00 -0000	[thread overview]
Message-ID: <bug-53861-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53861

             Bug #: 53861
           Summary: Assignment of an array element from pointer is not
                    taken as ARRAY_TYPE when expand_assignment
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zhenqiang.chen@linaro.org


In expr.c, there are comments and codes in function expand_assignment.

 /* Assignment of a structure component needs special treatment
     if the structure component's rtx is not simply a MEM.
     Assignment of an array element at a constant index, and assignment of
     an array element in an unaligned packed structure field, has the same
     problem.  Same for (partially) storing into a non-memory object.  */
  if (handled_component_p (to)
      || (TREE_CODE (to) == MEM_REF
          && mem_ref_refers_to_non_mem_p (to))
      || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)

But if an array element is accessed from a pointer, the condition check will
fail. Here is an example:

void test1( unsigned char* t, unsigned char* t1);
void test (int i, int j)
{
  unsigned char *p;
  unsigned char a1[16];
  unsigned char a[8];
  p = &a;
  p[1] = 1;
  p[3] = 3;
  a1[2] = 6;
  test1(a, a1);
}

Compile it with -O2/Os. The t.c.149t.optimized is like:

;; Function test (test, funcdef_no=0, decl_uid=4059, cgraph_uid=0)
test (int i, int j)
{
  unsigned char a[8];
  unsigned char a1[16];
<bb 2>:
  MEM[(unsigned char *)&a + 1B] = 1;
  MEM[(unsigned char *)&a + 3B] = 3;
  a1[2] = 6;
  test1 (&a, &a1);
  a1 ={v} {CLOBBER};
  a ={v} {CLOBBER};
  return;
}

The MEM_REF is not taken as an array element access. Then their address will be
simplified based on the sp during expanding. But in some targets (like ARM
THUMB1), sp can not be used in some sore instructions, we have to reset the
base address from sp before each reference.

If we take the MEM_REF as ARRAY_TYPE (by tracing its operand's TREE_TYPE, we
can find it is from ARRAY_TYPE), we can keep the index mode during expanding.

After that, if the targets support sp used in store instructions (like X86,
MIPS, ARM THUMB2 etc), fwprop1 can optimized it. Otherwise, just keep the index
mode, then we need only set the base address once.


             reply	other threads:[~2012-07-05  8:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  8:32 zhenqiang.chen at linaro dot org [this message]
2012-07-05  8:44 ` [Bug rtl-optimization/53861] " rguenth at gcc dot gnu.org
2021-12-19  0:35 ` [Bug middle-end/53861] " 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-53861-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).