The code was only checking for memory side-effects, but not for divergence side-effects. Replace this with a generic check. (cherry picked from commit 2e101cca)