Menu

#549 Trivial missing optimisation on Z80

None
closed
None
5
2018-05-17
2017-12-14
Alan Cox
No

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.

Discussion

  • Philipp Klaus Krause

    Ticket moved from /p/sdcc/bugs/2698/

    Can't be converted:

    • _category: Z80
     
  • Philipp Klaus Krause

    This optimization would be something to look into soon after the 3.7.0 release.

    Philipp

     
  • Philipp Klaus Krause

    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

     
  • Philipp Klaus Krause

    I can't reproduce this in current SDCC, and get:

    ld  hl, (_foo)
    ld  a, h
    and a, #0x01
    ld  h, a
    

    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

     
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
    • Group: -->
     
  • Philipp Klaus Krause

    • status: open --> closed
     
  • Philipp Klaus Krause

    Closing, since it can't be reproduced in current SDCC:

    Philipp

     

Log in to post a comment.

MongoDB Logo MongoDB