User Details
- User Since
- Aug 7 2020, 10:38 PM (104 w, 5 d)
Aug 10 2020
What would be a main benefit for allowing out-of-order execution between instructions having no data dependency in a sequential program?
Aug 9 2020
Excellent! Observability is key. If the value of n computed by the loop is not observable, the loop can be thrown out. If you want the computation in the loop to be observable, observe the n after the loop is done (or a bunch of other things that will work - like, call some "IO" or "OS" function).
the compiled program must only exhibit behaviors that were possible behaviors of the source program
I am going to add that the optimization is on the same lines as the more common case:
fn some_fn(y) { x = y % 42; if y < 0 return 0; ... }
Modern CPUs will attempt to divide, compare and prefetch the code on the predicted success branch in parallel, as and when the corresponding processing units become available. That is, it is possible that for negative y the return of 0 will be observed by the caller before the division is completed. The simple consequence is that the only way you can detect that the division has not started, is to write the code that will test the division outcome.
Aug 8 2020
In general, it is *not* valid for a compiler to remove an infinite loop.
Aug 7 2020
I am unable to go through all the examples of infinite loops, but please consider that it is not so much about forward progress in many cases.