This shows up a fair bit in my code, although longs in general are badly handled
static uint32_t foo;
uint16_t blkoff(void)
{
return foo & 511;
}
Generates a 32bit load into HL/BC and then masks H nicely. It should have generated a 16bit load
Even casting the value before doing the & 511 doesn't get rid of the bogus loads.
Ticket moved from /p/sdcc/bugs/2698/
Can't be converted:
This optimization would be something to look into soon after the 3.7.0 release.
Philipp
I've put this onto the TODO list for 3.8.0 in the wiki. I'll also have a look at Coremark for Z80; Coremark is mostly a 32-bit integer benchmark, so it might cover a few similar issues.
Philipp
I can't reproduce this in current SDCC, and get:
Which looks good to me. I tried with 32-bit and 64-bit foo. Do you still see unnecessary loads into registers for this code?
If yes, which SDCC version and options are used?
Philipp
Closing, since it can't be reproduced in current SDCC:
Philipp