This change adds a new hook for estimating the cost of cast instructions within
a given context. The hook differs from the existing context-free hook in that
clients can provide information about the cast's known operand or user.
The change is motivated by sign extensions, which on AArch64 can often be
folded into other instructions and are free. For example, a vector extract
followed by a sign extension can be performed by smov. And a vector subtraction
whose operands are both vector sign extensions can be performed by ssubl. And
so on.
While context is generally not a desirable feature to include in the cost
model, the fact that these extensions are often free may make them special
enough to warrant the added complexity.
The default implementation of the hook uses the context-free estimate. For
AArch64, I've added logic to cover the extract-extend pattern and the
lengthening and widening operations I mentioned above. The intent is to quickly
and simply identify the cases in which the cast is free, and to fall back on
the default implementation otherwise.
For an initial client, I've modified the cast estimates in the SLP vectorizer
to provide the additional context when known and thought to be useful.
I feel that this structure should contain EITHER an anonymous opcode (as it currently does) OR a Value*.
I think it is not worthwhile to have the user reencode their use-def graph for the purposes of passing as context. What we need to be able to say is "I'm going to insert $OPCODE and it's going to use these values". Some of the values may be yet to be inserted - so these could be anonymous too. But encoding the entire use-def graph to an arbitrary depth sounds like wasted effort. The code below for AArch64 seems to look quite deep at the graph too.