[PATCH][DAGCombiner] insert_vector_elt: Avoid to create multiple uses of the same load.

Quentin Colombet qcolombet at apple.com
Wed Jul 24 17:35:04 PDT 2013


Hi,

Here is a patch that prevents DAGCombiner to combine insert_vector_elt and build_vector nodes into build_vector nodes when it creates multiple uses of the same load.


** Context **

Prior to this patch DAGCombine combines insert_vector_elt nodes with constant indexes and build_vector nodes into build_vector nodes.
I.e.,
insert_vector_elt (build_vector elt0, …, eltN), NewEltIdx, idx
=>
build_vector elt0, …, NewEltIdx, …, eltN

This has the advantage of flattening the DAG and making the vectors more obvious.
However, if both build_vector nodes are meant to exist side by side, elt0 to eltN now have two users instead of one.

If one of this element is a load, this will prevent all folding opportunities.


** Example **

a = load
b = load
c = load
V1 = insert_vector undef, a, 0 // create a new vector form a
V2 = insert_vector V1, b, 1    // create a new vector V1 | b
V3 = insert_vector V1, c, 1    // create a new vector V1 | c

During DAG combine, this is optimized into:
a = load
b = load
c = load
V2 = build_vector a, b    // create a new vector a | b
V3 = build_vector a, c    // create a new vector a | c

Now the load of ‘a’ has two users. This is what it is exposed in the test case of the patch.


** Proposed Solution **

When combining an insert_vector_elt with a build_vector, we check if the vectors (the one issued from the insert_vector_elt and the one issued from the initial build_vector) are meant to exist side by side.
If they are, we check all the sources that will be duplicated from the input vector (i.e., all but eltIdx in the argument of the input build_vector) and when one of them is a load then do not combine.

To sum up:
- check if the resulting vector will live with the input vector.
- if yes, check the arguments of the input vector.
   - if one of the argument is a load used only once: do not combine as it will create an unfoldable load.


Thanks for the reviews.

Cheers,

-Quentin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130724/f63d9c9f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InsertVectorCombine.svndiff
Type: application/octet-stream
Size: 3083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130724/f63d9c9f/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130724/f63d9c9f/attachment-0001.html>


More information about the llvm-commits mailing list