This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/86073] New: -O3 arm generates calls to memset even for known at the compile time very small sizes (<=3)


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

            Bug ID: 86073
           Summary: -O3 arm generates calls to memset even for known at
                    the compile time very small sizes (<=3)
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pj at hugeone dot co.uk
  Target Milestone: ---

The test code:

void *my_memset1(void *ptr, const int v, size_t size)
{
    size_t rem = size & 3;
    size_t pro = (4 - ((uint32_t)ptr & 3)) & 3;
    uint32_t v32 = *(uint32_t *)ptr = (((unsigned)v) << 24) | (((unsigned)v) <<
16) | (((unsigned)v) << 8) | v;
    void *retval = ptr;

    pro = pro >= size ? pro : size;
    size -= pro;
    while(pro--)
    {
        *(uint8_t *)ptr++ = v;
    }
    size >>= 2;
    while(size--)
    {
        *(uint32_t *)ptr = v32;
        ptr+=4;
    }

    while(rem--)
    {
        *(uint8_t *)ptr++ = v;
    }
    return retval;
}

rem is always <= 3
pro is always <= 3

both generate call to the buikt in memset function


my_memset1:
  push {r3, r4, r5, r6, r7, r8, r9, lr}
  lsls r5, r1, #16
  negs r3, r0
  and r3, r3, #3
  orr r5, r5, r1, lsl #24
  orrs r5, r5, r1
  cmp r3, r2
  orr r5, r5, r1, lsl #8
  it cc
  movcc r3, r2
  mov r7, r1
  mov r8, r0
  str r5, [r0]
  subs r6, r2, r3
  and r9, r2, #3
  cbz r3, .L13
  mov r2, r3
  uxtb r1, r1
  mov r4, r3
  bl memset           <<--- here
  lsrs r0, r6, #2
  add r3, r8, r4
  beq .L14
.L20:
  add r0, r3, r0, lsl #2
.L11:
  str r5, [r3], #4
  cmp r3, r0
  bne .L11
.L10:
  cmp r9, #0
  beq .L12
  mov r2, r9
  uxtb r1, r7
  bl memset        <<---- here
.L12:
  mov r0, r8
  pop {r3, r4, r5, r6, r7, r8, r9, pc}
.L13:
  mov r3, r0
  lsrs r0, r6, #2
  bne .L20
.L14:
  mov r0, r3
  b .L10

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]