Optimizer: Fixed bug in foreach with ranges. The foreach range optimizer didn't handle negative start ranges, which would cause foreach to index the array out of bounds. Fixes [bug 7216 (#7216)].