public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
@ 2011-12-30  2:27 johnvb at broadcom dot com
  2011-12-30  2:28 ` [Bug target/51709] " johnvb at broadcom dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: johnvb at broadcom dot com @ 2011-12-30  2:27 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51709
           Summary: armv7 target is not using unaligned access to packed
                    fields sometimes (halfwords, loads?)
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: johnvb@broadcom.com


armv7 target is not always producing unaligned access to packed fields using
the appropriate half and full word instructions.  Rather sometimes it uses
bytes accesses with shifts and or's.

Below is a program which produces the problem:

typedef unsigned char  uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;

#define HALFWORD 1
#define ADD_BYTE 0
#define PACKED 1

#if HALFWORD
#define FIELD_T uint16
#else
#define FIELD_T uint32
#endif

#if PACKED
#define PACKED_ATTRIBUTE __attribute__ ((packed))
#else
#define PACKED_ATTRIBUTE
#endif

typedef struct PACKED_ATTRIBUTE {
#if ADD_BYTE
        uint8  field0;
#endif
        FIELD_T field1;
        FIELD_T field2;
} packed_struct_t;

typedef struct {
#if ADD_BYTE
        uint8  field0;
#endif
        FIELD_T field1;
        FIELD_T field2;
} natural_struct_t;

void
test_function(natural_struct_t *natural, packed_struct_t *packed)
{
        natural->field1 = packed->field1;
        packed->field2 = natural->field2;
}

This produces

test_function:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldrb    r3, [r1, #1]    @ zero_extendqisi2      @ tmp141,
        ldrb    ip, [r1, #0]    @ zero_extendqisi2      @ tmp140,* packed
        orr     r2, ip, r3, lsl #8      @, tmp143, tmp140, tmp141,
        ldrh    r3, [r0, #2]    @, natural_3(D)->field2
        strh    r2, [r0, #0]    @ movhi @ tmp143, natural_3(D)->field1
        strh    r3, [r1, #2]    @ unaligned     @ natural_3(D)->field2,
        bx      lr      @
        .size   test_function, .-test_function
        .ident  "GCC: (Sourcery CodeBench Lite 2011.09-69) 4.6.1"

The load from the packed structure is decomposed to byte accesses but note the
stores are not.  Also if you try full words by changing the define HALFWORD the
generated code is as expected.  Adding a byte to the beginning of the packed
and natural structure by changing the define ADD_BYTE doesn't change the
results.  It appears to only be the half word load that is having the problem.  

Note in the above assembly output, that the @unaligned is missing from the load
though present on the store.  If you look at the assembly for the full word
compile, the @unaligned is present on both the load and store.

I claim this is a sometimes result because I have looked at cases in my more
complicated source and I can see that sometimes packed half word loads do not
use byte accesses.


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

* [Bug target/51709] armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
  2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
  2011-12-30  2:28 ` [Bug target/51709] " johnvb at broadcom dot com
@ 2011-12-30  2:28 ` johnvb at broadcom dot com
  2011-12-30  3:24 ` johnvb at broadcom dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: johnvb at broadcom dot com @ 2011-12-30  2:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from John A. Van Boxtel <johnvb at broadcom dot com> 2011-12-30 02:27:15 UTC ---
Created attachment 26201
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26201
gcc_armv7_unaligned_test.c


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

* [Bug target/51709] armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
  2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
@ 2011-12-30  2:28 ` johnvb at broadcom dot com
  2011-12-30  2:28 ` johnvb at broadcom dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: johnvb at broadcom dot com @ 2011-12-30  2:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from John A. Van Boxtel <johnvb at broadcom dot com> 2011-12-30 02:27:51 UTC ---
Created attachment 26202
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26202
gcc_armv7_unaligned_test.i


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

* [Bug target/51709] armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
  2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
  2011-12-30  2:28 ` [Bug target/51709] " johnvb at broadcom dot com
  2011-12-30  2:28 ` johnvb at broadcom dot com
@ 2011-12-30  3:24 ` johnvb at broadcom dot com
  2012-01-13 15:41 ` ramana at gcc dot gnu.org
  2012-01-13 18:59 ` johnvb at broadcom dot com
  4 siblings, 0 replies; 6+ messages in thread
From: johnvb at broadcom dot com @ 2011-12-30  3:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from John A. Van Boxtel <johnvb at broadcom dot com> 2011-12-30 02:28:35 UTC ---
Created attachment 26203
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26203
gcc_armv7_unaligned_test.s


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

* [Bug target/51709] armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
  2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
                   ` (2 preceding siblings ...)
  2011-12-30  3:24 ` johnvb at broadcom dot com
@ 2012-01-13 15:41 ` ramana at gcc dot gnu.org
  2012-01-13 18:59 ` johnvb at broadcom dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ramana at gcc dot gnu.org @ 2012-01-13 15:41 UTC (permalink / raw)
  To: gcc-bugs

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

Ramana Radhakrishnan <ramana at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-01-13
                 CC|                            |ramana at gcc dot gnu.org
            Version|4.6.1                       |4.7.0
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #4 from Ramana Radhakrishnan <ramana at gcc dot gnu.org> 2012-01-13 14:07:53 UTC ---
Confirmed with GCC 4.7.0 on trunk . Reporting this for FSF GCC 4.6 is not
correct as unaligned access will only be in 4.7.0 when it is released. 

If you have an issue with the CS tools report at the appropriate place and not
here. 

cheers
Ramana


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

* [Bug target/51709] armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?)
  2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
                   ` (3 preceding siblings ...)
  2012-01-13 15:41 ` ramana at gcc dot gnu.org
@ 2012-01-13 18:59 ` johnvb at broadcom dot com
  4 siblings, 0 replies; 6+ messages in thread
From: johnvb at broadcom dot com @ 2012-01-13 18:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from John A. Van Boxtel <johnvb at broadcom dot com> 2012-01-13 18:39:43 UTC ---
Sorry about not understanding CS vs GNU release numbering and time
relationship.  I now understand that CS versions may precede introduction into
the GNC source.  I will also try to work with CS on reporting the bug.

I noticed this bug was listed as a code generation enhancement which I could
understand in a strict sense, i.e. the code generated works.  But given that
the compiler does create unaligned access to half words sometimes and in armv7,
there is no unaligned restrictions on normal half (or full) word access, this
seems like a significant code geneation issue for armv7 and makes one wonder if
the root cause might be more serious.

Constrast this with an architecture like x86 where unaligned access has always
been legal but if somehow the code generator used byte acesses, shifts and
and/or's to access (half) words.  This would be view as pretty "buggy".

Bottom line: I am just trying to make sure that the "enhancement" attribute
doesn't disqualify this from the current release cycle.  From that point of
view this seems like a bug to be fixed, not a future enhancement request.

Regards,

John A. Van Boxtel


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

end of thread, other threads:[~2012-01-13 18:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-30  2:27 [Bug target/51709] New: armv7 target is not using unaligned access to packed fields sometimes (halfwords, loads?) johnvb at broadcom dot com
2011-12-30  2:28 ` [Bug target/51709] " johnvb at broadcom dot com
2011-12-30  2:28 ` johnvb at broadcom dot com
2011-12-30  3:24 ` johnvb at broadcom dot com
2012-01-13 15:41 ` ramana at gcc dot gnu.org
2012-01-13 18:59 ` johnvb at broadcom dot com

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