<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div><br></div><div>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.</div><div><br></div><div><br></div><div>** Context **</div><div><br></div><div>Prior to this patch DAGCombine combines insert_vector_elt nodes with constant indexes and build_vector nodes into build_vector nodes.</div><div>I.e.,</div><div>insert_vector_elt (build_vector elt0, …, eltN), NewEltIdx, idx</div><div>=></div><div>build_vector elt0, …, NewEltIdx, …, eltN</div><div><br></div><div>This has the advantage of flattening the DAG and making the vectors more obvious.</div><div>However, if both build_vector nodes are meant to exist side by side, elt0 to eltN now have two users instead of one.</div><div><br></div><div>If one of this element is a load, this will prevent all folding opportunities.</div><div><br></div><div><br></div><div>** Example **</div><div><br></div><div><div>a = load</div><div>b = load</div><div>c = load</div><div>V1 = insert_vector undef, a, 0 // create a new vector form a</div><div>V2 = insert_vector V1, b, 1    // create a new vector V1 | b</div><div>V3 = insert_vector V1, c, 1    // create a new vector V1 | c</div></div><div><br></div><div><div>During DAG combine, this is optimized into:</div><div>a = load</div><div>b = load</div><div>c = load</div><div>V2 = build_vector a, b    // create a new vector a | b</div><div>V3 = build_vector a, c    // create a new vector a | c</div><div><br></div><div>Now the load of ‘a’ has two users. This is what it is exposed in the test case of the patch.</div><div><br></div><div><br></div><div>** Proposed Solution **</div><div><br></div><div>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.</div><div>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.</div><div><br></div><div>To sum up:</div><div>- check if the resulting vector will live with the input vector.</div><div>- if yes, check the arguments of the input vector.</div><div>   - if one of the argument is a load used only once: do not combine as it will create an unfoldable load.</div><div><br></div><div><br></div><div>Thanks for the reviews.</div><div><br></div><div>Cheers,</div><div><br></div><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica;  font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">-Quentin</div>

</div>
</div></body></html>