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 rtl-optimization/66248] New: subreg truncation not hoisted from loop


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

            Bug ID: 66248
           Summary: subreg truncation not hoisted from loop
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jon at beniston dot com
  Target Milestone: ---

In the following code, where 'short' is 16-bits, on 32-bit processors
(ARM/MIPS/SPARC targets), the code that is generated to truncate the value of
the variable 'ret' to 16-bits (typically a shift left then right), appears in
each iteration of the loop.

short func(short *a, int y)
{
 short ret;
 int i;
 for(i = 0; i < y; i++) 
   ret += a[i];

 return ret;
}

E.g. on ARM at -O2/3:

.L3:
        ldrh    r2, [r0], #2
        add     r3, r2, r3
        mov     r3, r3, asl #16
        cmp     r0, r1
        mov     r3, r3, lsr #16
        bne     .L3


Should these not be hoisted out of the loop and only executed once before the
return?


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