On 7/5/2017 4:48 PM, H. S. Teoh via Digitalmars-d-announce wrote:
In particular, it doesn't seem to do code hoisting, as least
not for this case,
It does not in this case because:
i.e. a read through a pointer. Inside the loop, there is also:
data[i * 10] = ...
which is an assignment through a pointer. The assignment through the pointer
makes a read through a pointer not loop invariant. It's only possible to pull
out the assignment to j if loop unrolling is done, which as I said is not done
Loop invariant removal (aka code hoisting) *is* done in the optimizer.
> There are two calls to _d_arrayboundsp inside the loop body, along with
branches around them. This seems needless, since one bounds check ought to be
enough to ensure the array lookups are within bounds. Also, there are 2 branches
within the loop body (not counting the end-of-loop branch), whereas it could
have been simplified to one (less branch hazards on the CPU pipeline).
Yes, that's true, I'm not sure why that isn't happening. It should be.