Compiler should optimize 'for' loops in the near zero range
by 'lagprogramming'.
Must be marked as related to #40370 (Compiler should optimize some comparisons with -1).
-
for signedvariable:=value to -1 do
produces code where the value of a register is compared with -1. -
for (un)signedvariable:=value downto 1 do
produces code where the value of a register is compared with 1.
In both cases the compiler might produce code that compares with 0, not with 1 or -1 because, depending on the target, it may optimize the comparisons. For example:
- instead of cmp a register value with 1 and then jumping on the condition >=1, it's better to test the register and then jump on the condition >0.
- instead of cmp a register value with -1 and then jumping on the condition <=-1, it's better to test the register and then jump on the condition <0.
Edited by Alexey Torgashin