Oleg Endo - 2023-07-30

Looking at a smaller snippet of a larger function:

    ....
    mov dptr,#(_var + 0x0014)
    movx    a,@dptr
    mov r6,a               
    cjne    a,#0x02,00276$
    sjmp    00124$
00276$:
    mov dptr,#(_var + 0x0014)
    clr a
    movx    @dptr,a
    sjmp    00124$
00109$:
    mov dptr,#(_var + 0x000d)
    movx    a,@dptr
    mov r6,a                   <<<<<<<<<<<<<< dead move 
    cjne    a,#0x01,00277$
    sjmp    00124$
00277$:
    mov dptr,#(_var + 0x000d)
    clr a
    movx    @dptr,a
00124$:
    mov dpl,r7
    ret

When the above marked mov r6,a is checked whether it's a dead move or not, the doTermScan / scan4op code visits labels 00277 and 00124.

'checkLabelRef' bails out at label 00124 because at that point (for this particular dead-move check) the label ref count = 10 and the jump-to-count is only 1, as inspected by this dead-move check. There are many other parts higher up in the function that jump to label 00124, hence its high ref count.

It looks like the checkLabelRef check in removeDeadMove is superflous.
In the above case we can see that the approach doesn't work as it is anticipated in the code.