Menu

#984 suboptimal register use (seen in dumpralloccon)

open
nobody
None
5
2025-02-01
2025-02-01
No

On Z80, at least, the following function could use only two 8-bit registers (for c and n) and one register pair for the address p:

char gg( char c, char* p ) {
    char n = 5;
    do {
        if ( c & 1 )
            return *p;
        c >>= 1;
        p++;
    } while ( --n );
    return 0;
}

The resulting code (TD- 4.5.0 #15240 (MINGW64)) is, however:

; Function gg
; ---------------------------------
_gg::
    ld  l, e
    ld  h, d
    ld  b, #0x05
00103$:
    bit 0, a
    jr  Z, 00102$
    ld  a, (hl)
    ret
00102$:
    srl a
    inc de
    ld  l, e
    ld  h, d
    djnz    00103$
    ld  a, b
    ret

Both HL and DE are used for the same content.

dumpralloccon dot shows 6 dependent iTemp nodes (0-5):

graph G {
0[label="0 : iTemp0:0"];
1[label="1 : iTemp1:0"];
2[label="2 : iTemp1:1"];
3[label="3 : iTemp9:0"];
4[label="4 : iTemp9:1"];
5[label="5 : iTemp10:0"];
6[label="6 : iTemp6:0"];
1--2 ;
3--4 ;
0--1 ;
0--2 ;
0--3 ;
0--4 ;
1--3 ;
1--4 ;
2--3 ;
2--4 ;
0--5 ;
1--5 ;
2--5 ;
3--5 ;
4--5 ;
}

I suspect the reason for too many registers used are two nodes (a register pair) that shouldn't add to the complexity but are introduced and also stay, and that it's not happening only for Z80 port, but is a more general issue.

Attached: the graph from dumpralloccon.dot and the dumprassgn text output

1 Attachments

Discussion


Log in to post a comment.

MongoDB Logo MongoDB