<div dir="ltr"><div>I naively replicated what was done for other intrinsics in this file. Later I started to realize that might not be right. We handle the demanded elts for the operands in InstCombineCalls, but I think that circuments the has one use early in SimplifyDemandedElts since we come in with Depth of 0. I plan to fix the demanded elements in this code, and then just make InstCombineCalls call SimplifyDemandedElts on the Intrinsic instruction with an all ones mask. Then this code will deal with the operands and have a depth of 1 in their call. This is similar to what Insert element does.</div><div><br><div class="gmail_quote"><div>On Mon, Dec 12, 2016 at 11:46 AM Friedman, Eli <<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/11/2016 12:54 AM, Craig Topper via llvm-commits wrote:<br class="m_3617286402384373510gmail_msg"><br>> Author: ctopper<br class="m_3617286402384373510gmail_msg"><br>> Date: Sun Dec 11 02:54:52 2016<br class="m_3617286402384373510gmail_msg"><br>> New Revision: 289377<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=289377&view=rev" rel="noreferrer" class="m_3617286402384373510gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=289377&view=rev</a><br class="m_3617286402384373510gmail_msg"><br>> Log:<br class="m_3617286402384373510gmail_msg"><br>> [X86][InstCombine] Add support for scalar FMA intrinsics to SimplifyDemandedVectorElts.<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>> This teaches SimplifyDemandedElts that the FMA can be removed if the lower element isn't used. It also teaches it that if upper elements of the first operand aren't used then we can simplify them.<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>> Modified:<br class="m_3617286402384373510gmail_msg"><br>>      llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp<br class="m_3617286402384373510gmail_msg"><br>>      llvm/trunk/test/Transforms/<wbr>InstCombine/x86-fma.ll<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>> Modified: llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp<br class="m_3617286402384373510gmail_msg"><br>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=289377&r1=289376&r2=289377&view=diff" rel="noreferrer" class="m_3617286402384373510gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp?rev=289377&r1=289376&r2=<wbr>289377&view=diff</a><br class="m_3617286402384373510gmail_msg"><br>> ==============================<wbr>==============================<wbr>==================<br class="m_3617286402384373510gmail_msg"><br>> --- llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp (original)<br class="m_3617286402384373510gmail_msg"><br>> +++ llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineSimplifyDemanded.<wbr>cpp Sun Dec 11 02:54:52 2016<br class="m_3617286402384373510gmail_msg"><br>> @@ -981,6 +981,7 @@ Value *InstCombiner::<wbr>SimplifyDemandedVec<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>>     bool MadeChange = false;<br class="m_3617286402384373510gmail_msg"><br>>     APInt UndefElts2(VWidth, 0);<br class="m_3617286402384373510gmail_msg"><br>> +  APInt UndefElts3(VWidth, 0);<br class="m_3617286402384373510gmail_msg"><br>>     Value *TmpV;<br class="m_3617286402384373510gmail_msg"><br>>     switch (I->getOpcode()) {<br class="m_3617286402384373510gmail_msg"><br>>     default: break;<br class="m_3617286402384373510gmail_msg"><br>> @@ -1298,6 +1299,34 @@ Value *InstCombiner::<wbr>SimplifyDemandedVec<br class="m_3617286402384373510gmail_msg"><br>>         UndefElts &= UndefElts2;<br class="m_3617286402384373510gmail_msg"><br>>         break;<br class="m_3617286402384373510gmail_msg"><br>><br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfmadd_ss:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfmsub_ss:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfnmadd_ss:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfnmsub_ss:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfmadd_sd:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfmsub_sd:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfnmadd_sd:<br class="m_3617286402384373510gmail_msg"><br>> +    case Intrinsic::x86_fma_vfnmsub_sd:<br class="m_3617286402384373510gmail_msg"><br>> +      TmpV = SimplifyDemandedVectorElts(II-<wbr>>getArgOperand(0), DemandedElts,<br class="m_3617286402384373510gmail_msg"><br>> +                                        UndefElts, Depth + 1);<br class="m_3617286402384373510gmail_msg"><br>> +      if (TmpV) { II->setArgOperand(0, TmpV); MadeChange = true; }<br class="m_3617286402384373510gmail_msg"><br>> +      TmpV = SimplifyDemandedVectorElts(II-<wbr>>getArgOperand(1), DemandedElts,<br class="m_3617286402384373510gmail_msg"><br>> +                                        UndefElts2, Depth + 1);<br class="m_3617286402384373510gmail_msg"><br>> +      if (TmpV) { II->setArgOperand(1, TmpV); MadeChange = true; }<br class="m_3617286402384373510gmail_msg"><br>> +      TmpV = SimplifyDemandedVectorElts(II-<wbr>>getArgOperand(2), DemandedElts,<br class="m_3617286402384373510gmail_msg"><br>> +                                        UndefElts3, Depth + 1);<br class="m_3617286402384373510gmail_msg"><br>> +      if (TmpV) { II->setArgOperand(2, TmpV); MadeChange = true; }<br class="m_3617286402384373510gmail_msg"><br>> +<br class="m_3617286402384373510gmail_msg"><br>> +      // If lowest element of a scalar op isn't used then use Arg0.<br class="m_3617286402384373510gmail_msg"><br>> +      if (DemandedElts.getLoBits(1) != 1)<br class="m_3617286402384373510gmail_msg"><br>> +        return II->getArgOperand(0);<br class="m_3617286402384373510gmail_msg"><br>> +<br class="m_3617286402384373510gmail_msg"><br>> +      // Output elements are undefined if all three are undefined.  Consider<br class="m_3617286402384373510gmail_msg"><br>> +      // things like undef&0.  The result is known zero, not undef.<br class="m_3617286402384373510gmail_msg"><br>> +      UndefElts &= UndefElts2;<br class="m_3617286402384373510gmail_msg"><br>> +      UndefElts &= UndefElts3;<br class="m_3617286402384373510gmail_msg"><br>> +      break;<br class="m_3617286402384373510gmail_msg"><br>> +<br class="m_3617286402384373510gmail_msg"><br><br class="m_3617286402384373510gmail_msg"><br>This looks really weird... for the second and third operands, shouldn't<br class="m_3617286402384373510gmail_msg"><br>we only be demanding the bottom element?  In the same way, we only care<br class="m_3617286402384373510gmail_msg"><br>whether the bottom element is undef.<br class="m_3617286402384373510gmail_msg"><br><br class="m_3617286402384373510gmail_msg"><br>-Eli<br class="m_3617286402384373510gmail_msg"><br><br class="m_3617286402384373510gmail_msg"><br>--<br class="m_3617286402384373510gmail_msg"><br>Employee of Qualcomm Innovation Center, Inc.<br class="m_3617286402384373510gmail_msg"><br>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br class="m_3617286402384373510gmail_msg"><br><br class="m_3617286402384373510gmail_msg"><br></blockquote></div></div></div>