[ScalarEvolution] Re-enable Predicate implication from operations
authorMax Kazantsev <max.kazantsev@azul.com>
Fri, 24 Mar 2017 06:19:00 +0000 (06:19 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Fri, 24 Mar 2017 06:19:00 +0000 (06:19 +0000)
commit89554446e77c39502bb0893bcda4f151f124b5b8
tree3ce1ac643214049eef605e8f7ecae1b41750a671
parentc97d8aa86650ed795bf75a7dd735ecfaef3b8f55
[ScalarEvolution] Re-enable Predicate implication from operations

The patch rL298481 was reverted due to crash on clang-with-lto-ubuntu build.
The reason of the crash was type mismatch between either a or b and RHS in the following situation:

  LHS = sext(a +nsw b) > RHS.

This is quite rare, but still possible situation. Normally we need to cast all {a, b, RHS} to their widest type.
But we try to avoid creation of new SCEV that are not constants to avoid initiating recursive analysis that
can take a lot of time and/or cache a bad value for iterations number. To deal with this, in this patch we
reject this case and will not try to analyze it if the type of sum doesn't match with the type of RHS. In this
situation we don't need to create any non-constant SCEVs.

This patch also adds an assertion to the method IsProvedViaContext so that we could fail on it and not
go further into range analysis etc (because in some situations these analyzes succeed even when the passed
arguments have wrong types, what should not normally happen).

The patch also contains a fix for a problem with too narrow scope of the analysis caused by wrong
usage of predicates in recursive invocations.

The regression test on the said failure: test/Analysis/ScalarEvolution/implied-via-addition.ll

llvm-svn: 298690
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/implied-via-addition.ll [new file with mode: 0644]
llvm/test/Analysis/ScalarEvolution/implied-via-division.ll [new file with mode: 0644]