[llvm-dev] [RFC][SDAG] Convert build_vector of ops on extractelts into ops on input vectors

Nemanja Ivanovic via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 10 13:49:58 PST 2020

I have added a few PPC-specific DAG combines in the past that follow this
pattern on specific operations. Now that it appears that this would be
useful to do on yet another operation, I'm wondering what people think
about doing this in the target-independent DAG Combiner for any
legal/custom operation on the target.

The generic pattern would look like this:

(build_vector (op (extractelt %a, 0), [(extractelt %b, 0)]...),
              (op (extractelt %a, 1), [(extractelt %b, 1)]...), ...)

Basically, if the build vector is built from the same operation
applied on elements extracted from another vector (or pair of vectors
for binary ops), then we can check for the legality of the operation
on the vector type. If the operation is legal for the vector type (and
the operand and result vector types are the same), then we can just
convert this to

(op %a [, %b])

Which is likely going to produce better code in all cases. Of course,
things like this have a tendency to not be better in all cases, but I
think we can probably account for any corner cases that arise.

(v2i64 build_vector (mulhs (extractelt %a, 0), (extractelt %b, 0)),
                    (mulhs (extractelt %a, 1), (extractelt %b, 1)))

Can be converted to the following on a target that has the operation
available on vectors.
(v2i64 mulhs %a, %b)

A further improvement might be if the order of extracted elements
doesn't match the order in the build_vector, that we shuffle one or
both input vectors prior to applying the operation.

If you think this is a good idea (or a terrible idea), please let me know.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200110/e6825707/attachment.html>

More information about the llvm-dev mailing list