[SCEV] Be less conservative when extending bitwidths for computing ranges.
authorMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 20 Dec 2016 23:03:42 +0000 (23:03 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 20 Dec 2016 23:03:42 +0000 (23:03 +0000)
commite909a6ed355e50bf558d920176a9a81ae07b779b
tree656fafc539929743edb5863e8c951b37f19925d4
parent4f392d3fa3867a053ce0ac4282e456d7c4392697
[SCEV] Be less conservative when extending bitwidths for computing ranges.

Summary:
In getRangeForAffineAR we compute ranges for affine exprs E = A + B*C,
where ranges for A, B, and C are known. To avoid overflow, we need to
operate on a bigger bitwidth, and originally we chose 2*x+1 for this
(x being the original bitwidth). However, it is safe to use just 2*x:

A+B*C <= (2^x - 1) + (2^x - 1)*(2^x - 1) =
       =  2^x - 1 + 2^2x - 2^x - 2^x + 1 =
       = 2^2x - 2^x <= 2^2x - 1

Unnecessary extending of bitwidths results in noticeable slowdowns: ranges
perform arithmetic operations using APInt, which are much slower when bitwidths
are bigger than 64.

Reviewers: sanjoy, majnemer, chandlerc

Subscribers: llvm-commits

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

llvm-svn: 290211
llvm/lib/Analysis/ScalarEvolution.cpp