[AMDGPU] SIMemoryLegalizer: Factor out check if memory operations can affect the global AS (#160129)
Mostly NFC, and adds an assertion for gfx12 to ensure that no atomic scratch
instructions are present in the case of GloballyAddressableScratch. This should
always hold because of #154710.