#314 Optimize simple assignments using ld a,(nnnn)

open
nobody
z80 port (30)
5
2011-03-22
2011-03-22
Anonymous
No

I am using sdcc for gbz80. Had a look at the generated assembly and was surprised to see this code:

ld hl,#_MY_GLOBAL_VAR
ld a,(hl)

Why is not simply this generated?

ld a,(_MY_GLOBAL_VAR)

Regards,
Johan

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2011-03-22
    • summary: Optimize simple assignments using ld a,(hl) --> Optimize simple assignments using ld a,(nnnn)
     
  • Philipp Klaus Krause

    The optimization should be done in the peephole optimizer. Currently there are nearly no peephole rules enabled for gbz80. Someone should go through all z80 peephole rules and add those that would work on the gbz80 to the gbz80 rules.

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2011-04-19

    Since the peephole optimizer is a time expensive part of the compilation it would be advantageous to try to put this optimization in the code generator.

     
  • Philipp Klaus Krause

    With the new register allocation this situation changes drastically:

    1) The register allocator needs a lot of time
    2) The code is much better already after code generation, thus we can remove many existing peephole rules

    The reason current code genration goes through hl is this:
    We might need the same value in hl later on, thus it might be better to put it into hl, just in case: The peephole optimizer can optimize it out if not.

    In the long run IMO, this should be solved using rematerializeable variables, allowing the register allocator to make this decision. The new allocator is expensive in terms of run time, but it gives optimality.

    Philipp

    P.S.: This comment applies top both the z80 and gbz80 ports.

     

Log in to post a comment.