理论上说,如果列入<条码>(<>>>>>>,则有可能实现最佳化,则汇编者必须加以优化。
- Detect that you are testing specifically a "less than" condition
- Prove that the loop (assume one exists for the purposes of this discussion) results in a variable increasing monotonically
- Prove that there are no observable side effects from the loop body
That s a big bunch of things to count on IMHO, and it includes features which are not "obviously useful" in other contexts as well. Keep in mind that compiler vendors have limited resources so there has to be really good justification for implementing these prerequisites and having the compiler bring all the parts together to optimize this case.
Seeing as even if this is a perf issue for someone the problem can be easily solved in code, I don t feel that there would be such justification. So no, generally you should not expect cases like this to be optimized.