[Bug target/63742] New: arm *movhi_insn_arch4 pattern may emit ldrh which is wrong for big-endian

fei.yang0953 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Nov 5 06:49:00 GMT 2014


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

            Bug ID: 63742
           Summary: arm *movhi_insn_arch4 pattern may emit ldrh which is
                    wrong for big-endian
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fei.yang0953 at gmail dot com
                CC: ramana.radhakrishnan at arm dot com
              Host: x86_64-suse-linux
            Target: armeb-linux-gnueabi-gcc
             Build: x86_64-suse-linux

Simple testcase (test.c):

unsigned short v;
int i;
int j = 0;
int *ptr = &j;

unsigned short func()
{

  for (i = 0; i < 1; ++i)
    {
       *ptr = -1;
       v = 0x1234;
    }

  return v;
}

Compile option: armeb-linux-gnueabi-gcc -S -O1 test.c

Assembly code snippet:
func:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        str     lr, [sp, #-4]!
        movw    r3, #:lower16:i
        movt    r3, #:upper16:i
        mov     r2, #0
        str     r2, [r3]
        movw    r0, #:lower16:.LANCHOR0
        movt    r0, #:upper16:.LANCHOR0
        mvn     lr, #0
        movw    r1, #:lower16:v
        movt    r1, #:upper16:v
        ldrh    ip, .L5 @ movhi
        mov     r2, r3
.L2:
        ldr     r3, [r0]
        str     lr, [r3]
        strh    ip, [r1]        @ movhi
        ldr     r3, [r2]
        add     r3, r3, #1
        str     r3, [r2]
        cmp     r3, #0
        ble     .L2
        movw    r3, #:lower16:v
        movt    r3, #:upper16:v
        ldrh    r0, [r3]
        ldr     pc, [sp], #4
.L6:
        .align  2
.L5:
        .word   4660

Issue under big-endian:
  The ldrh loads the wrong value as immediate 4660 is in big-endian form.

GCC version: gcc version 5.0.0 20141026 (experimental)



More information about the Gcc-bugs mailing list