[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 --- Comment #12 from Oleg Endo --- (In reply to Oleg Endo from comment #0) > The following code: > > struct X > { > int a, b, c, d, e; > }; > > int test (X* x, unsigned int c) > { > int s = 0; > unsigned int i; > for (i = 0; i < c; ++i) > s += x[i].b; > return s; > } > > results in: > tst r5,r5 > bt/s.L4 > mov r5,r1 > shll2 r1 > add r5,r1 > mov.l .L9,r2 > shll2 r1 > add #-20,r1 > shlr2 r1 > mul.l r2,r1 > mov.l .L10,r2 > add #4,r4 > mov #0,r0 > sts macl,r1 > and r2,r1 > add #1,r1 > .L3: > mov.l @r4,r2 > dt r1 > add #20,r4 > bf/s.L3 > add r2,r0 > rts > nop > .L4: > rts > mov #0,r0 > .L11: > .align 2 > .L9: > .long 214748365 > .L10: > .long 1073741823 > As of GCC 13, this still produces the same code with loop header bloat.
[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 Richard Biener changed: What|Removed |Added Status|NEW |ASSIGNED
[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 Oleg Endo changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=62233, ||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=60537 --- Comment #11 from Oleg Endo --- And still on SH, but now with AMS optimization: char* test_func_00 (char* p, int c, int x) { do { *--p = (char)x; *--p = (char)x; *--p = (char)x; } while (--c); return p; } Results in: mov r5,r7 mov.l .L6,r1 add r7,r7 mov r7,r2 add r5,r2 mul.l r1,r2 mov r4,r3 exts.b r6,r6 add #-3,r3 sts macl,r0 .align 2 .L2: mov r3,r2 add #3,r2 mov.b r6,@-r2 dt r0 mov.b r6,@-r2 mov.b r6,@r3 mov r2,r3 bf/s.L2 add #-4,r3 add r5,r7 mov r4,r0 rts sub r7,r0 .L7: .align 2 .L6: .long -1431655765 And with -fno-ivopts we're getting something what one would expect: exts.b r6,r6 mov r4,r1 mov r5,r2 .align 2 .L2: mov.b r6,@-r1 dt r2 mov.b r6,@-r1 bf/s.L2 mov.b r6,@-r1 mov r5,r0 shll2 r0 sub r0,r5 mov r4,r0 rts add r5,r0
[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 Alan Modra changed: What|Removed |Added Target|sh*-*-* arm*-*-*|sh*-*-* arm*-*-* ||powerpc*-*-* CC||amodra at gmail dot com --- Comment #10 from Alan Modra --- Seen also on powerpc. Even for simple testcases like int b[30]; void fn1 (unsigned int n) { unsigned int i; for (i = 0; i < n; i++) b[i] = 42; } I see for -m32 fn1: cmpwi 0,3,0 beq 0,.L1 slwi 9,3,2 lis 10,b-4@ha addi 9,9,-4 la 10,b-4@l(10) srwi 9,9,2 li 8,42 addi 9,9,1 mtctr 9 .p2align 4,,15 .L3: stwu 8,4(10) bdnz .L3 .L1: blr All of the insns marked are redundant. For -m64 this loop doesn't even use bdnz Loop 1 is simple: simple exit 4 -> 5 infinite if: (expr_list:REG_DEP_TRUE (ne:SI (and:DI (plus:DI (minus:DI (ashift:DI (reg:DI 189) (const_int 2 [0x2])) (reg:DI 179 [ ivtmp.7 ])) (symbol_ref:DI ("b") [flags 0x80] )) (const_int 3 [0x3])) (const_int 0 [0])) (nil)) number of iterations: (lshiftrt:DI (plus:DI (minus:DI (reg:DI 185 [ _18 ]) (reg:DI 179 [ ivtmp.7 ])) (const_int -4 [0xfffc])) (const_int 2 [0x2])) upper bound: 29 likely upper bound: 29 realistic bound: -1 Doloop: Possible infinite iteration case. Doloop: The loop is not suitable.
[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 --- Comment #9 from Oleg Endo --- As of r233601 the issue still persists.
[Bug rtl-optimization/55190] ivopts causes loop setup bloat
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55190 --- Comment #8 from Oleg Endo --- I've adjusted the title, since the issues here are not SH specific. There is also a similar PR 62233.