Extended UB analysis of SCEV with the case where an instruction marked as non-wrapping (I) is later used in a latch control expression. In this case, if I holds a poison value, the loop can be made to iterate forever which is undefined behavior.
For wrapping of I to be UB, the latch control expression must execute if I is executed. To proof this, the PostDominatorTree is needed by SCEV. If a post-domination path is found, it is checked that progress from I to the latch control expression is guaranteed. That is, trapping instruction and infinite loops must be absent on that execution path.
This patch is 1/2 to fix PR28429. Known issues:
- Contains a work around for the LoopPassManager that has trouble with the newly added dependency of the PostDominator pass. This can be approved upon to make the PostDominatorTree pass run less often
- LoopUnroll uses SCEV and breaks PostDominatorTree, giving an segfault if a function contains multiple loops.
I hope to get a review to see if this work is OK to commit once the known issues listed above are fixed.
If you also check that useI is a TerminatorInst then you'll keep the SmallPtrSet smaller.