Bug Fixes
- arr[i] in for-loop inside function returned arr[0] for every i — LICM (Loop-Invariant Code Motion) incorrectly hoisted loop-counter-indexed array reads as invariant when BCE (Bounds Check Elimination) didn't fire. Two root causes:
- BCE Pattern 4 didn't recognize module-level
constlimits (e.g.,const MAX_COINS = 100) becauseis_integer=falsedespite havingconst_valueset — addedconst_valuecheck collect_assigned_idsonly scanned the loop body, missing theupdateexpression (i = i + 1) where the counter is assigned — LICM then treatedarr[i]as invariant and hoisted it withi=0
- BCE Pattern 4 didn't recognize module-level
Tests
- Added
tests/test_array_index_loop.tsregression test for array index access in for-loops inside functions with many module-level arrays