<div dir="ltr"><div>As a general rule, InstCombine tries not increase the total number of instructions. If X/Y has another use other than this one, then it still ends up being calculated. Without the one use check you'd trade 2 fdivs, for 1 mul (Y * Z), and 2 fdivs ((X*Y)/Z) and the original (X / Y). </div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 30, 2019 at 4:07 PM raghesh via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Dear All,<div><br></div><div>The <span id="gmail-m_4463031153282372788:2a4.1">InstCombine</span> pass performs the following transformation.</div><div><br></div><div> Z / (X / Y) => (Y * Z) / X<br></div><div><br></div><div>This is performed only when operand Op1 ( (X/Y) in this case) has only one use in future. The code snippet is shown below.</div><div><br></div><div> if (match(Op1, m_<span id="gmail-m_4463031153282372788:2a4.2">OneUse</span>(m_<span id="gmail-m_4463031153282372788:2a4.3">FDiv</span>(m_Value(X), m_Value(Y)))) &&<br> (!<span id="gmail-m_4463031153282372788:2a4.4">isa</span><Constant>(Y) || !<span id="gmail-m_4463031153282372788:2a4.5">isa</span><Constant>(Op0))) {<br> // Z / (X / Y) => (Y * Z) / X<br> Value *<span id="gmail-m_4463031153282372788:2a4.6">YZ</span> = Builder.<span id="gmail-m_4463031153282372788:2a4.7">CreateFMulFMF</span>(Y, Op0, &I);<br> return <span id="gmail-m_4463031153282372788:2a4.8">BinaryOperator</span>::<span id="gmail-m_4463031153282372788:2a4.9">CreateFDivFMF</span>(<span id="gmail-m_4463031153282372788:2a4.10">YZ</span>, X, &I);<br> }</div><div><br></div><div>It would be great if someone explains if there is any issue (correctness/performance-wise) if we avoid the m_<span id="gmail-m_4463031153282372788:2a4.11">OueUse</span> check. What if we perform the transformation even if there are multiple uses?</div><div><br></div><div>There are similar transformations which perform the
m_<span id="gmail-m_4463031153282372788:2a4.12">OueUse</span> check. We may avoid those too if there is no particular reason for the check.</div><div><br></div><div>Regards,<br><div><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>------------------------------</div><div><span id="gmail-m_4463031153282372788:2a4.13">Raghesh</span> <span id="gmail-m_4463031153282372788:2a4.14">Aloor</span></div><div><span id="gmail-m_4463031153282372788:2a4.15">AMD</span> India Pvt. Ltd.</div><div><span id="gmail-m_4463031153282372788:2a4.16">Bengaluru</span>.</div><div>------------------------------</div></div></div></div></div></div></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>