Fix for https://bugs.llvm.org/show_bug.cgi?id=31181. When LFTR moves a condition prior to increment to a condition after increment, it may depend on a value that is now poison due to nowrap flags. We need to make sure to drop the nowrap flags on the add in such a situation. I'm doing this by copying the nowrap flags that SCEV computed.
Once this issue is fixed, we can reenable computation of nowrap flags in CVP.
I don't think the no-wrap flags on the SCEV expression can be propagated to the increment operation like this. I wrote up some background here: https://www.playingwithpointers.com/blog/scev-integer-overflow.html but in short, say your pre-increment SCEV expression is {S,+,X} then the post-inc SCEV expression, SE->getSCEV(CmpIndVar) down below, is {S+X,+,X}. Whether this is nsw/nuw has nothing to do with whether S+X can overflow -- all it says is that on all but the last iteration of the loop Add(CmpIndVar,X) will not overflow where CmpIndVar starts from S+X and is incremented by X on every iteration.
As a concrete example, say the pre-increment expression is {-1,+,1} and let's say the loop body executes 10 times. Then the post-inc IV is {0,+,1}, which is both nuw and nsw (the value of the IV is < 10 and adding 1 to it does not overflow). But you can't mark the increment operation as nuw because on the very first iteration it computes Add(-1,1) which unsigned overflows.