http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57540

--- Comment #1 from bin.cheng <amker.cheng at gmail dot com> ---
The dump of loop_init is like,
   72: r178:SI=0
  106: L106:
   90: NOTE_INSN_BASIC_BLOCK 6
   91: r178:SI=r178:SI+0x1
   94: r190:SI=r177:SI<<0x2
      REG_DEAD r177:SI
   95: r191:SI=sfp:SI+r190:SI
      REG_DEAD r190:SI
   96: r192:SI=r191:SI-0x810
      REG_DEAD r191:SI
      REG_DEAD r189:SI
   97: r177:SI=[r192:SI]
      REG_DEAD r192:SI
   98: cc:CC=cmp(r177:SI,0)
   99: pc={(cc:CC>=0)?L104:pc}
      REG_DEAD cc:CC
      REG_BR_PROB 0x238c

Instructions 95/96 should be re-factored as below:
   95: r191:SI=sfp:SI-0x810
      REG_DEAD r190:SI
   96: r192:SI=r191:SI+r190:SI
      REG_DEAD r191:SI
      REG_DEAD r189:SI

Thus instruction 95 is loop invariant and be hoisted. For arm target, the loop
can be simplified into:

    blt    .L3

.L5:
    add    r2, r2, #1
    ldr    r3, [sp, r3, asl #2]
    cmp    r3, #0
    bge    .L5
    uxtb    r2, r2

Reply via email to