Loop strength reduction for array indexing
Indexing into a
ByteArray# in a loop is currently more expensive than working on a
ForeignPtr due to lack of strength reduction. Pointer arithmetic is cheaper than using base + offset indexing. We could convert indexing into pointer arithmetic if it weren't for the GC being able to move objects around.
Tom Rodriguez had the following to say about Java HotSpot and loop strength reduction:
"The server compiler doesn't do explicit loop strength reduction though it can get a bit of it as a result of other transformations loop invariant code motion. I've played a bit with doing it more explicitly but had some difficulty getting benefit from it. The resulting pointers are handled by the notion of derived pointers. These are interior pointers that are tracked along with their base pointers. At the beginning of GC the offset from the base of the derived pointer is saved and the pointer is converted to the base and after GC the offset is added back in. That part all happens automatically. Searching for DerivedPointer will lead you to the relevant code."
Perhaps it's an idea we could try?