In CodeGen prepare we have optimization which re-creates some derived pointers instead of using gc.relocates for them. I.e if we had following code:
%derived = gep %base, 15 safepoint(base, derived) %base.rel = gc.relocate(%base) %derived.rel = gc.relocate(%derived)
It transforms it into:
%derived = gep %base, 15 safepoint(base, derived) %base.rel = gc.relocate(%base) %derived.rel = gep %base.rel, 15
This is profitable for pointers which are cheaply computed from their bases.
In this changeset I am moving this optimization from CodeGenPrepare into RewriteSafepointPass. Basic motivation here is that by doing it before gc.relocate insertion we can catch substantially more cases. For example if pointer is located inside a loop with statepoint.
Also I am extending it to happen not only on geps with small constant indices, but on all geps and noop casts.