Here are some common patterns that can be optimized (based on usages in khicas on ez80-clang 19.1.0):
361 times:
; current
rlc a
sbc hl, hl
; optimal
rlca
sbc hl, hl
97 times:
; current
ld l, a
rlc l
sbc hl, hl
; optimal
rlca
rrca ; note that this can be removed all bits in A are the same (so A = 0 or A = -1)
sbc hl, hl
250 times:
; current
rlc a
sbc a, a
; optimal
rlca
sbc a, a
I suppose more generally, rlc a and rrc a can be transformed into rlca and rrca if only the carry flag is needed
Here are some common patterns that can be optimized (based on usages in khicas on ez80-clang 19.1.0):
361 times:
97 times:
250 times:
I suppose more generally,
rlc aandrrc acan be transformed intorlcaandrrcaif only the carry flag is needed