Fixes PR31517
I'm not 100% sure about this fix. The problem is we don't check if the last load aliases anything, so this now checks all instructions to see if they alias and adds stores to the alias set. However I'm not sure if memcpy/memset or any other ways of writing need to be handled specially here.