#10 Optimization: Track State of ACC & DPTR


Here's another opportunity for optimization. In the following code, the compiler doesn't
recognize that the accumulator (used to store the constant '1') isn't changing. The same is true
for the DPTR in the second example.


xdata volatile char a, b, c, d;

void f2( void )
a = 1; // Accumulator doesn't change.
b = 1;
c = 1;
d = 1;

void f3( void )
a = 1; // DPTR doesn't change.
a = 2;
a = 3;
a = 4;


  • Frieder Ferlemann

    Logged In: YES
    Originator: NO

    Optimization of f2() is addressed by SDCC 2.6.4 #4634.

    Registers R0..R7 and the accumulator are tracked.

    No tracking of DPTR (and symbols) yet. So while
    f3() is three byte shorter there still are multiple
    "mov dptr,#_a" generated for f3().

    Set environment variable SDCC_RTRACK to enable
    this optimization.

  • Frieder Ferlemann

    • assigned_to: nobody --> frief
  • Frieder Ferlemann

    Implemented in SDCC 2.9.7 #5697 (Feb 19 2010).

    Set an environment variable SDCC_REGTRACK if you want
    to enable register tracking.
    If you want diagnostic output use option --fverbose-asm
    and additionally set SDCC_REGTRACK_VERBOSE

    The plan would be to remove the environment variable
    SDCC_REGTRACK later, make register tracking the
    default behaviour and have a compiler option
    --no-regtrack then.
    "Then" probably means after the next release:)

    (note, I renamed the environment variable to the
    slightly more descriptive SDCC_REGTRACK)

  • Maarten Brock

    Maarten Brock - 2013-11-16

    Enabled register tracking by default in SDCC #8897.
    There is no --no-regtrack yet.

    N.B. DPL/DPH tracking often defeats MOV DPTR,#... optimization and is therefor not present.


Log in to post a comment.