[ScalarEvolution] Re-enable Predicate implication from operations
authorMax Kazantsev <max.kazantsev@azul.com>
Fri, 31 Mar 2017 12:05:30 +0000 (12:05 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Fri, 31 Mar 2017 12:05:30 +0000 (12:05 +0000)
commit2e44d2969af826efa5bfb271f403ac86428d68fb
treeb780d2d403fc92c1f3f8c6d725e419fee06624c6
parent72b3357f2d39adb0cf88fef992cd2570452d90ac
[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

Reviewers: reames, apilipenko, anna, sanjoy

Reviewed By: sanjoy

Subscribers: mzolotukhin, mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D31238

llvm-svn: 299205
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]