[SCEV] Fix trip multiple calculation
authorEli Friedman <efriedma@codeaurora.org>
Mon, 20 Mar 2017 20:25:46 +0000 (20:25 +0000)
committerEli Friedman <efriedma@codeaurora.org>
Mon, 20 Mar 2017 20:25:46 +0000 (20:25 +0000)
commitb1578d36129c731b9348781aead3227a3c299223
treef68d90436a6c8720c777d35a95ee7fe28283c91a
parent6043e0f7388225f0aa0624adf8b9e0c631259bd7
[SCEV] Fix trip multiple calculation

If loop bound containing calculations like min(a,b), the Scalar
Evolution API getSmallConstantTripMultiple returns 4294967295 "-1"
as the trip multiple. The problem is that, SCEV use -1 * umax to
represent umin. The multiple constant -1 was returned, and the logic
of guarding against huge trip counts was skipped. Because -1 has 32
active bits.

The fix attempt to factor more general cases. First try to get the
greatest power of two divisor of trip count expression. In case
overflow happens, the trip count expression is still divisible by the
greatest power of two divisor returned. Returns 1 if not divisible by 2.

Patch by Huihui Zhang <huihuiz@codeaurora.org>

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

llvm-svn: 298301
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/tripmultiple_calculation.ll [new file with mode: 0644]