Page MenuHomePhabricator

[Support] Introduce a new InstructionCost class

Authored by david-arm on Nov 10 2020, 8:42 AM.



This is the first in a series of patches that attempts to migrate
existing cost instructions to return a new InstructionCost class
in place of a simple integer. This new class is intended to be
as light-weight and simple as possible, with a full range of
arithmetic and comparison operators that largely mirror the same
sets of operations on basic types, such as integers. The main
advantage to using an InstructionCost is that it can encode a
particular cost state in addition to a value. The initial
implementation only has two states - Normal and Invalid - but these
could be expanded over time if necessary. An invalid state can
be used to represent an unknown cost or an instruction that is
prohibitively expensive.

This patch adds the new class and changes the getInstructionCost
interface to return the new class. Other cost functions, such as
getUserCost, etc., will be migrated in future patches as I believe
this to be less disruptive. One benefit of this new class is that
it provides a way to unify many of the magic costs in the codebase
where the cost is set to a deliberately high number to prevent
optimisations taking place, e.g. vectorization. It also provides
a route to represent the extremely high, and unknown, cost of
scalarization of scalable vectors, which is not currently supported.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
david-arm marked 6 inline comments as done.Dec 10 2020, 1:30 AM

Please add the asserts in SLPVectorizer, and then this looks good to me.


NIT: If we're adding an assert in LoopVectorize, then these three getValues should also get asserts.

david-arm updated this revision to Diff 310880.Dec 10 2020, 7:02 AM
david-arm marked an inline comment as done.
RKSimon accepted this revision.Dec 10 2020, 8:22 AM

LGTM - cheers

This revision was automatically updated to reflect the committed changes.