This patch centralizes all the combines of add|sub|mul with extended operands in one "framework".
The rationale for this change is to offer a one-stop-shop for all these transformations so that, in the future (next patch), it is easier to make combine decisions for a web of instructions (i.e., instructions connected through s|zext operands).
Technically this patch is not NFC because the new version is more powerful than the previous version.
In particular, it diverges in two cases:
- VWMULSU can now also be produced from mul(splat, zext), whereas previously only mul(sext, splat) were supported when splats were involved. (As demonstrated in rvv/fixed-vectors-vwmulsu.ll)
- VWSUB(U) can now also be produced from sub(splat, ext), whereas previously only sub(ext, splat) were supported when splats were involved. (As demonstrated in rvv/fixed-vectors-vwsub.ll)
If we wanted, we could block these transformations to make this patch really NFC. For instance, we could do something similar to AllowSplatInVW_W, which prevents the combines to form vw(add|sub)(u)_w when the RHS is a splat.
Regarding the "framework" itself, the bulk of the patch is some boilerplate code that abstracts away the actual extensions that are present in the DAG. This allows us to handle vwadd_w(ext a, b) as if it was a regular add(ext a, ext b). Since the node ext b doesn't actually exist in the DAG, we have a bunch of methods (all in the NodeExtensionHelper class) that fake all that for us.
The other half of the change is around CombineToTry and CombineResult. These helper structures respectively:
- Represent the kind of combines that can be applied to a node, and
- Store what needs to happen to do that combine.
This can be viewed as a two step approach:
- First, check if a pattern applies, and
- Second apply it.
The checks and the materialization of the combines are decoupled so that in the future we can perform several checks and do all the related applies in one go.
Everything in this anonymous namespace is the boilderplate code I was talking about in the description.