#2282 labelInRage() of STM8 peephole is not accurate

closed-fixed
Ben Shi
None
STM8
5
2015-01-29
2014-07-09
Ben Shi
No

With the attached a.c:

extern int ss(int, int, int, int);
extern void qq();

int sad(int a, int b)
{
_ee:
ss(1,2,3,4);
ss(1,2,3,4);
ss(1,2,3,4);
ss(1,2,3,4);
qq();
qq();
qq();
qq();

    a++;
    if (!a)
            return b;
    else
            b--;

    goto _ee;

}

the following asm is generated:

  000000                         47 _sad:
  000000 52 04            [ 2]   48         sub     sp, #4
                                 49 ;       a.c: 6: _ee:
  000002 16 09            [ 2]   50         ldw     y, (0x09, sp)
  000004 17 03            [ 2]   51         ldw     (0x03, sp), y
  000006 16 07            [ 2]   52         ldw     y, (0x07, sp)
  000008 17 01            [ 2]   53         ldw     (0x01, sp), y
  00000A                         54 00101$:
                                 55 ;       a.c: 7: ss(1,2,3,4);
  00000A 4B 04            [ 1]   56         push    #0x04
  00000C 4B 00            [ 1]   57         push    #0x00
  ......
  000077                        117 00103$:
                                118 ;       a.c: 20: b--;
  000077 1E 03            [ 2]  119         ldw     x, (0x03, sp)
  000079 5A               [ 2]  120         decw    x
  00007A 1F 03            [ 2]  121         ldw     (0x03, sp), x
                                122 ;       a.c: 22: goto _ee;
  00007C CCr00r0A         [ 2]  123         jp      00101$
  00007F                        124 00105$:
  00007F 5B 04            [ 2]  125         addw    sp, #4
  000081 81               [ 4]  126         ret

the jp->jra peephole rule is not triggered, where jp@0x007C should be a jra, though (0x81 - 0x0A) is still in range (-128, 127).

As far as my test, the actual trigger range is (-115, 114).

1 Attachments
a.c

Discussion

  • Ben Shi

    Ben Shi - 2014-07-15

    Fix in rev9049. Now the goto (JP) statement in the attached a.c is optimized to JRA, and the trigger range is improved to (-125, 124).

     
  • Ben Shi

    Ben Shi - 2014-07-15
    • status: open --> closed-fixed
    • assigned_to: Ben Shi
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks