This option is switched off by default, and it seems that it has never worked correctly.
What it basically does is: it remembers current BECount SCEV, and after all transforms
tries to validate some facts for it. However, between these two points this SCEV may
become invalid (e.g. because some SCEVUnknown it references may be deleted as dead
code). So basically it may work with broken pointers.
Besides, its implementation does strange things (e.g. forgetLoop) which are invasive and
may affect behavior in other parts of the system (specifically verification), concealing some
other problems. Another issue is that it may use SCEVCouldNotCompute object without
checking this.
The option is not used in any unit tests, and if switched on by default, the following tests
fail:
******************** Failed Tests (14): LLVM :: Transforms/IndVarSimplify/2005-06-15-InstMoveCrash.ll LLVM :: Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll LLVM :: Transforms/IndVarSimplify/2008-10-03-CouldNotCompute.ll LLVM :: Transforms/IndVarSimplify/2009-05-24-useafterfree.ll LLVM :: Transforms/IndVarSimplify/2011-10-27-lftrnull.ll LLVM :: Transforms/IndVarSimplify/ARM/code-size.ll LLVM :: Transforms/IndVarSimplify/X86/deterministic-scev-verify.ll LLVM :: Transforms/IndVarSimplify/X86/pr57187.ll LLVM :: Transforms/IndVarSimplify/X86/verify-scev.ll LLVM :: Transforms/IndVarSimplify/bbi-63564.ll LLVM :: Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll LLVM :: Transforms/IndVarSimplify/loop-predication.ll LLVM :: Transforms/IndVarSimplify/post-inc-range.ll LLVM :: Transforms/IndVarSimplify/turn-to-invariant.ll ******************** Unexpectedly Passed Tests (1): LLVM :: Transforms/IndVarSimplify/pr55689.ll
None of these looks like real problems found by verification, these are
bugs in the verifying code itself (such as use of deleted SCEVs and
SCEVCouldNotCompute's).
I think it all gives enough justification for its removal.
You can drop the ifndef -- we generally don't place VerifyMemorySSA behind NDEBUG, because you need to enable it via a flag anyway.