[SCEV] Clarify requirements for zero-stride to be UB
authorPhilip Reames <listmail@philipreames.com>
Wed, 1 Sep 2021 20:56:25 +0000 (13:56 -0700)
committerPhilip Reames <listmail@philipreames.com>
Wed, 1 Sep 2021 21:01:13 +0000 (14:01 -0700)
commit73b951a7f7dc07be37bcb3d545d228098c4e19f4
treeb105dd6300fd1b19d55fa48cba76c8e302bdde5b
parent06cdf48a0d94749a19b0b7075a8baf9d979bb409
[SCEV] Clarify requirements for zero-stride to be UB

There's a silent bug in our reasoning about zero strides. We assume that having a single static exit implies that if that exit is not taken, then the loop must be infinite. This ignores the potential for abnormal exits via exceptions. Consider the following example:

for (uint_8 i = 0; i < 1; i += 0) {
  throw_on_thousandth_call();
}

Our reasoning is such that we'd conclude this loop can't take the backedge as that would lead to a (presumed) infinite loop.

In practice, this is a silent bug because the loopIsFiniteByAssumption returns false strictly more often than the loopHaNoAbnormalExits property. We could reasonable want to change that in the future, so fixing the codeflow now is worthwhile.

Differential Revision: https://reviews.llvm.org/D109029
llvm/lib/Analysis/ScalarEvolution.cpp