public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/53861] New: Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment
@ 2012-07-05  8:32 zhenqiang.chen at linaro dot org
  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
  0 siblings, 2 replies; 3+ messages in thread
From: zhenqiang.chen at linaro dot org @ 2012-07-05  8:32 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/53861] Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment
  2012-07-05  8:32 [Bug rtl-optimization/53861] New: Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment zhenqiang.chen at linaro dot org
@ 2012-07-05  8:44 ` rguenth at gcc dot gnu.org
  2021-12-19  0:35 ` [Bug middle-end/53861] " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-05  8:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-05 08:44:02 UTC ---
You should be able to use index mode for expanding

 MEM[(unsigned char *)&a + 1B]

as well.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/53861] Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment
  2012-07-05  8:32 [Bug rtl-optimization/53861] New: Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment zhenqiang.chen at linaro dot org
  2012-07-05  8:44 ` [Bug rtl-optimization/53861] " rguenth at gcc dot gnu.org
@ 2021-12-19  0:35 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-19  0:35 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|rtl-optimization            |middle-end
           Keywords|                            |missed-optimization

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm:
;; MEM[(unsigned char *)&a + 1B] = 1;

(insn 7 6 8 (set (reg:SI 115)
        (const_int 1 [0x1])) "/app/example.cpp":9:8 -1
     (nil))

(insn 8 7 9 (set (reg:QI 116)
        (subreg:QI (reg:SI 115) 0)) "/app/example.cpp":9:8 -1
     (nil))

(insn 9 8 0 (set (mem/c:QI (plus:SI (reg/f:SI 108 virtual-stack-vars)
                (const_int -23 [0xffffffffffffffe9])) [0 MEM[(unsigned char
*)&a + 1B]+0 S1 A8])
        (reg:QI 116)) "/app/example.cpp":9:8 -1
     (nil))

vs
;; a1[2] = 6;

(insn 13 12 14 (set (reg:SI 119)
        (const_int 6 [0x6])) "/app/example.cpp":11:9 -1
     (nil))

(insn 14 13 15 (set (reg:QI 120)
        (subreg:QI (reg:SI 119) 0)) "/app/example.cpp":11:9 -1
     (nil))

(insn 15 14 0 (set (mem/c:QI (plus:SI (reg/f:SI 108 virtual-stack-vars)
                (const_int -14 [0xfffffffffffffff2])) [0 a1[2]+0 S1 A16])
        (reg:QI 120)) "/app/example.cpp":11:9 -1
     (nil))

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-19  0:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-05  8:32 [Bug rtl-optimization/53861] New: Assignment of an array element from pointer is not taken as ARRAY_TYPE when expand_assignment zhenqiang.chen at linaro dot org
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

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