[Bug target/62233] unnecessary shift instructions to prepare loop counter

2023-07-06 Thread olegendo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62233

Oleg Endo  changed:

   What|Removed |Added

 CC||olegendo at gcc dot gnu.org

--- Comment #4 from Oleg Endo  ---
Looks like with GCC 13 it now converts the loop into a memset call.

typedef struct {
  int l;
  int b[258];
} S;

void clear2 (S* s )
{
   int i;
   int len = s->l;

   int* p = s->b;
   for (i = 0; i < len; i++)
   p[i] = 0;
}

compiling with GCC 13 -mlra -m2 -ml -O2:

mov.l   @r4+,r6 ! 6 [c=1 l=2]  movsi_i/5
cmp/pl  r6  ! 10[c=4 l=2]  cmpgtsi_t/0
bf.s.L1 ! 11[c=17 l=2]  *cbranch_t
shll2   r6  ! 16[c=4 l=2]  ashlsi3_k/1
mov.l   .L5,r0  ! 19[c=10 l=2]  movsi_i/0
jmp @r0 ! 20[c=5 l=2]  sibcall_valuei
mov #0,r5   ! 17[c=4 l=2]  movsi_i/2
.align 1
.L1:
rts 
nop ! 41[c=0 l=4]  *return_i
.L6:
.align 2
.L5:
.long   _memset


However, compiling with GCC 13 -mlra -m2 -ml -O2 -fno-builtin results in pretty
much the same code as in comment #2

[Bug target/62233] unnecessary shift instructions to prepare loop counter

2017-03-14 Thread segher at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62233

Segher Boessenkool  changed:

   What|Removed |Added

 CC||segher at gcc dot gnu.org

--- Comment #3 from Segher Boessenkool  ---
Both trunk and 6 generate

rldicl 9,9,0,2

instead of the two shifts.  Still not ideal of course.

[Bug target/62233] unnecessary shift instructions to prepare loop counter

2014-09-25 Thread olegendo at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62233

Oleg Endo  changed:

   What|Removed |Added

 Target|powerpc64le |powerpc64le sh*-*-*
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2014-09-25
 CC||olegendo at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #2 from Oleg Endo  ---
On SH, the original code above looks OK (no extra shifts generated), however,
changing it to:

void clear2 (S* s )
{
   int i;
   int len = s->l;

   int* p = s->b;
   for (i = 0; i < len; i++)
   p[i] = 0;
}

results in:
mov.l   @r4,r1
cmp/pl  r1
bf/s.L13
add #4,r4
shll2   r1   
add #-4,r1   
shlr2   r1   
mov #0,r2
add #1,r1
.align 2
.L10:
mov.l   r2,@r4
dt  r1
bf/s.L10
add #4,r4
.L13:
rts
nop

This looks very similar to what is happening in PR 55190.
BTW, compiling the two functions with -O3 results in a detected memset, while
at -O2 a memset is not detected.


[Bug target/62233] unnecessary shift instructions to prepare loop counter

2014-08-22 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62233

--- Comment #1 from Andrew Pinski  ---
This again is related to bug 37451.