With typed pointers, InstCombine will often convert gep of addrspacecast into addrspacecast of gep, see e.g. https://llvm.godbolt.org/z/fYa3oKvdh. This isn't done consistently, because it happens as a side-effect of other folds. The most common one is trivial index descaling (where no descaling actually happens, and only the addrspacecast/gep end up being swapped). These folds are disabled for opaque pointers, so we don't canonicalize in either direction there.
This adds canonicalization of gep(ac) to ac(gep). I've limited this to the case where index types match: While this is always legal, changing index types might introduced truncs/sexts, which might be non-profitable (test diffs were a wash).
After typed pointer support is dropped, we might want to consider inverting this canonicalization and going from ac(gep) to gep(ac) instead, which seems better to me. But for now I'm matching what typed pointers were (mostly) doing.
We probably shouldn't be reassociating if either address space is non-integral. I think that was one of the fixes that never happened for the existing code