Skip to content

v1.0.5: Restore register keyword ZP optimization after Bug #179 fix #185

Description

@CTalkobt

Description

Bug #179 fix (commit 05010af) resolved a critical frame allocation conflict that was causing struct tm corruption when code was linked across translation units. However, this fix introduced a regression: the register keyword optimization no longer works.

Problem

The fix forces all locals to FRAME allocation to prevent overlaps with temporaries. This prevents register variables from being allocated to Zero Page (ZP), which was a performance optimization.

Before fix: register int x; → allocated to ZP (fast)
After fix: register int x; → allocated to FRAME (correct but slower)

Root Cause

The frame allocation reordering in IRCodeGen.cpp (lines 1015-1043) now allocates all locals to FRAME first, then temporaries. While this prevents corruption, it also prevents register variables from using the register keyword behavior.

Solution Needed

Refine the fix to allow register variables to be allocated to ZP while still protecting non-register locals from frame allocation conflicts. This requires:

  1. Distinguish between register and non-register locals in IRCodeGen
  2. Apply the FRAME-only restriction only to non-register locals
  3. Allow register locals to use ZP allocation when available
  4. Ensure no overlap occurs between any locals and temporaries

Testing

The failing test register int allocated in ZP in src/test-resources/test_register.c validates register keyword optimization.

References

Labels

enhancement, optimization, register-allocation


🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions