[ValueLattice] Steal bits from Tag to track range extensions (NFC).
authorFlorian Hahn <flo@fhahn.com>
Fri, 17 Apr 2020 14:30:00 +0000 (15:30 +0100)
committerFlorian Hahn <flo@fhahn.com>
Fri, 17 Apr 2020 14:38:23 +0000 (15:38 +0100)
commitc245d3e033a58582475c3d749085f47a9ab0dda1
treeb3d53089454bf2aa0accf49fb6a92bc31576dc13
parenta8e4b7a5504196fc920126fb1e71d221e3879545
[ValueLattice] Steal bits from Tag to track range extensions (NFC).

Users of ValueLatticeElement currently have to ensure constant ranges
are not extended indefinitely. For example, in SCCP, mergeIn goes to
overdefined if a constantrange value is repeatedly merged with larger
constantranges. This is a simple form of widening.

In some cases, this leads to an unnecessary loss of information and
things can be improved by allowing a small number of extensions in the
hope that a fixed point is reached after a small number of steps.

To make better decisions about widening, it is helpful to keep track of
the number of range extensions. That state is tied directly to a
concrete ValueLatticeElement and some unused bits in the class can be
used. The current patch preserves the existing behavior by default:
CheckWiden defaults to false and if CheckWiden is true, a single change
to the range is allowed.

Follow-up patches will slightly increase the threshold for widening.

Reviewers: efriedma, davide, mssimpso

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D78145
llvm/include/llvm/Analysis/ValueLattice.h
llvm/lib/Transforms/Scalar/SCCP.cpp