9 ms·
The compiler cannot optimize that into `while(true)` because the original code does not encounter undefined behavior when `limit` is small enough to fit into `i
by dgrunwald 15d ago
The compiler cannot optimize that into `while(true)` because the original code does not encounter undefined behavior when `limit` is small enough to fit into `int`.
What it can do: infer that `limit <= INT_MAX` and use that to optimize the code following after the loop (and in some cases, even the code before the loop).
- aka-rider 15d agoThis isn't complete example. I don't remember the details unfortunately. But somehow compiler has decided that i <= limit is always true.