A few things I'm not sure about.
- Is this the right place to do it? (It seems that this is used in both instcombine and jumpthreading with a similar pattern but I'm not sure if this can be triggerred in jumpthreading)
- Do I need the address space check? I can't find a different place that checks the address space matching and the caller does not try addrspacecast (and probably shouldn't) though I also can't trigger the code with two address space ....