[SCEV] Replace assert with returning CouldNotComp in computeMaxBECountForLT.
authorFlorian Hahn <flo@fhahn.com>
Wed, 19 Oct 2022 10:24:10 +0000 (11:24 +0100)
committerFlorian Hahn <flo@fhahn.com>
Wed, 19 Oct 2022 10:24:10 +0000 (11:24 +0100)
commit1625224fbb7b911d492437c1613d83e1f85efb9e
tree94c835f9d621fc5eb7bce1c442dde2b091916c64
parent38f3e44997f06b4a0d176aff4ec09839a99d5f51
[SCEV] Replace assert with returning CouldNotComp in computeMaxBECountForLT.

This patch removes the bail out for signed predicates and non-positive
strides in howManyLessThans and updates computeMaxBECountForLT to return
SCEVCouldNotCompute for signed predicates with negative strides.

AFAICT bail-out was only added because computeMaxBECountForLT may not
handle negative signed strides correctly. Instead of not calling
computeMaxBECountForLT at all because we bail out earlier, we can
instead return SCEVCouldNotCompute in computeMaxBECountForLT.

The max backedge taken count will be computed as the max value of the
symbolic backedge taken count.

This improves precision in cases where we can compute symbolic backedge
taken counts and also fixes a crash.

Fixes #57818.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D135667
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/max-trip-count.ll
llvm/test/Analysis/ScalarEvolution/trip-count-negative-stride.ll