CodeGen: Make atomic operations play nice with address spaces

We were being a little sloppy with our pointer/address space casts.

This fixes PR21643.