This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Be less conservative when extending bitwidths for computing ranges.
ClosedPublic

Authored by mzolotukhin on Dec 14 2016, 6:59 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

mzolotukhin retitled this revision from to [SCEV] Be less conservative when extending bitwidths for computing ranges..
mzolotukhin updated this object.
mzolotukhin added reviewers: sanjoy, majnemer, chandlerc.
mzolotukhin added a subscriber: llvm-commits.
sanjoy accepted this revision.Dec 19 2016, 9:06 PM
sanjoy edited edge metadata.

lgtm

This revision is now accepted and ready to land.Dec 19 2016, 9:06 PM
This revision was automatically updated to reflect the committed changes.