nim-works / phy

compiler and vm experiments
MIT License
3 stars 2 forks source link

pass10: fix nested loop data-flow analysis #54

Closed zerbina closed 1 month ago

zerbina commented 1 month ago

Summary

Fix both the reaching definitions and liveness analysis not handling nested loops correctly, resulting in compiler crashes or miscompilation.

Details

Only iterating the outermost loop twice doesn't ensure that a fixpoint is reached -- it necessary to process every loop 2 + N times, where N is the nesting depth. The documentation of both analysis passes is improved to better describe what they do and why they work like they do.

Tests are added to ensure that nested loops are handled correctly. Except for t03_ssa_loop_4, the previous implementation produced incorrect code for the new tests.