[llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model

David Sherwood via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 5 07:42:34 PST 2020


I'd like to propose a change to our cost interfaces so that instead of returning
an unsigned value from functions like getInstructionCost, getUserCost, etc., we
instead return a wrapper class that encodes an integer cost along with extra
state. The extra state can be used to express:

1. A cost as infinitely expensive in order to prevent certain optimisations
taking place. For example, there are already examples in LLVM where the cost is
set extremely high, but not so high that it would cause overflow. This might be to
prevent vectorisation in cases where we would have to scalarize the operation,
which is particularly relevant for scalable vectors, where scalarisation is
not [yet] available. There isn't currently a standard value for something that
constitutes very expensive and we can replace all the magic numbers with a
single invalid state.
2. A cost as unknown, where the user is simply unable to determine an accurate
cost for an operation.

This new wrapper class would work almost seamlessly with existing code as it
would contain the full set of operators required for arithmetic and comparisons.
This is in addition to the ability to create invalid costs and query the validity
of an existing cost. Once a cost becomes invalid or unknown it will remain in that
state regardless of any further arithmetic performed.

Kind Regards,
David Sherwood.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201105/bafb3ae3/attachment.html>

More information about the llvm-dev mailing list