[ScalarEvolution] Fix overflow in computeBECount.
commitcbba71bfb50fb668b80ed430125a460279928272
authorEli Friedman <efriedma@quicinc.com>
Fri, 9 Jul 2021 21:10:44 +0000 (9 14:10 -0700)
committerEli Friedman <efriedma@quicinc.com>
Fri, 16 Jul 2021 23:15:18 +0000 (16 16:15 -0700)
tree6f9a892f3d236d4243725d354afea72b5f7031bc
parentb8355b71260e762af4e125a2241817cffe40bf4e
[ScalarEvolution] Fix overflow in computeBECount.

The current implementation of computeBECount doesn't account for the
possibility that adding "Stride - 1" to Delta might overflow. For almost
all loops, it doesn't, but it's not actually proven anywhere.

To deal with this, use a variety of tricks to try to prove that the
addition doesn't overflow.  If the proof is impossible, use an alternate
sequence which never overflows.

Differential Revision: https://reviews.llvm.org/D105216
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll
llvm/test/Analysis/ScalarEvolution/trip-count-unknown-stride.ll