<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 03/14/2017 07:16 AM, vivek pandya
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAHYgpoJBYB=inHJ7S1EwYz3b+hS99Li3ACVDXh4K1Qd2kryPmg@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <div dir="ltr">Hello Hal,
        <div>setCondCodeAction(expand) for un ordered comparison
          generates semantically wrong code for me for example SETUNE
          gets converted to SETOE that causes infinite loops.</div>
      </div>
    </blockquote>
    <br>
    Can you please explain what is happening? It sounds like a bug we
    should fix.<br>
    <br>
    <blockquote
cite="mid:CAHYgpoJBYB=inHJ7S1EwYz3b+hS99Li3ACVDXh4K1Qd2kryPmg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>What is ideal place where I can convert unordered
          comparison to un comparison + OR + ordered comparison ?</div>
        <div>Can I do it by adding required SDNodes ?</div>
        <div>for example I am trying to do it in LowerBR_CC as shown
          below:</div>
        <div>
          <div>      getFPCCtoMBCC(CC,TCC);</div>
          <div>      TargetCC = DAG.getConstant(TCC, dl, MVT::i8);</div>
          <div>      Flag = DAG.getNode(XXXISD::FCMP, dl, MVT::Glue,
            LHS, RHS,</div>
          <div>                         TargetCC);</div>
          <div>      if (isUnordered) {</div>
          <div>      TCC = XXX::COND_UN;</div>
          <div>      TargetCC = DAG.getConstant(TCC, dl, MVT::i8);</div>
          <div>      SDValue UnComp = DAG.getNode(XXX::FCMP, dl,
            MVT::Glue, LHS, RHS,</div>
          <div>                                   TargetCC);</div>
          <div>      Flag = DAG.getNode(ISD::OR, dl, MVT::Glue, Flag,
            UnComp);</div>
          <div>      }</div>
        </div>
        <div>but here I can't OR 2 MVT::Glue value.</div>
        <div>How can I compare results of two fcmp SDValue objs?</div>
      </div>
    </blockquote>
    <br>
    If your FCMP node sets some register, you'd need to read it
    (DAG.getCopyFromReg).<br>
    <br>
     -Hal<br>
    <br>
    <blockquote
cite="mid:CAHYgpoJBYB=inHJ7S1EwYz3b+hS99Li3ACVDXh4K1Qd2kryPmg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Please provide some guidance.</div>
        <div><br>
        </div>
        <div>Sincerely,</div>
        <div>Vivek</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Mar 9, 2017 at 10:29 PM, vivek
          pandya <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:vivekvpandya@gmail.com" target="_blank">vivekvpandya@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr"><br>
              <div class="gmail_extra"><br>
                <div class="gmail_quote">
                  <div>
                    <div class="h5">On Thu, Mar 9, 2017 at 9:35 PM, Hal
                      Finkel <span dir="ltr"><<a
                          moz-do-not-send="true"
                          href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span>
                      wrote:<br>
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex">
                        <div bgcolor="#FFFFFF" text="#000000">
                          <div>
                            <div class="m_7239601225858991101h5">
                              <p><br>
                              </p>
                              <div
                                class="m_7239601225858991101m_-2662977842983796072moz-cite-prefix">On
                                02/25/2017 03:06 AM, vivek pandya via
                                llvm-dev wrote:<br>
                              </div>
                              <blockquote type="cite">
                                <div dir="ltr">
                                  <div>Note: Question is written after
                                    describing what I have coded.<br>
                                  </div>
                                  <div><br>
                                  </div>
                                  <div>Hello LLVMDevs,</div>
                                  <div><br>
                                  </div>
                                  <div>I am trying to impliment floating
                                    point comparsion for an architecture
                                    which</div>
                                  <div>supports following type of
                                    floating point comparision if FPU is
                                    available:</div>
                                  <div>fcmp.un --> true if one of the
                                    operand is NaN</div>
                                  <div><a moz-do-not-send="true"
                                      href="http://fcmp.lt"
                                      target="_blank">fcmp.lt</a> -->
                                    ordered less than, if any input NaN
                                    then return false</div>
                                  <div>fcmp.eq --> ordered equal, if
                                    any input NaN then return false</div>
                                  <div>fcmp.le --> ordered less
                                    equal, if any input NaN then return
                                    false</div>
                                  <div><a moz-do-not-send="true"
                                      href="http://fcmp.gt"
                                      target="_blank">fcmp.gt</a> -->
                                    ordered grater than, if any input
                                    NaN then return false</div>
                                  <div><a moz-do-not-send="true"
                                      href="http://fcmp.ne"
                                      target="_blank">fcmp.ne</a> -->
                                    ordered not equal, if any input NaN
                                    then return true</div>
                                  <div><a moz-do-not-send="true"
                                      href="http://fcmp.ge"
                                      target="_blank">fcmp.ge</a> -->
                                    ordered grater equal, if any input
                                    NaN then return false</div>
                                  <div><br>
                                  </div>
                                  <div>When FPU is not present I need to
                                    generate a library call,</div>
                                  <div><br>
                                  </div>
                                  <div>so I have added following code in
                                    LowerBR_CC function in
                                    XXXISelLowering.cpp</div>
                                  <div><br>
                                  </div>
                                  <div>const XXXSubtarget &STI =
                                    static_cast<const
                                    XXXSubtarget&></div>
                                  <div>                                 
                                               (DAG.getSubtarget());</div>
                                  <div> XXXCC::CondCodes TCC;</div>
                                  <div> getFPCCtoXXCC(CC,TCC);</div>
                                  <div> TargetCC = DAG.getConstant(TCC,
                                    dl, MVT::i8);</div>
                                  <div> if (STI.useHardFloat()) {</div>
                                  <div>    // if fcmp instruction is
                                    available use it</div>
                                  <div>   SDValue Flag =
                                    DAG.getNode(XXXISD::FCMP, dl,
                                    MVT::Glue, LHS, RHS,</div>
                                  <div>                      TargetCC);</div>
                                  <div>   return
                                    DAG.getNode(XXXISD::BR_CC, dl,
                                    Op.getValueType(),</div>
                                  <div>                  Chain, Dest,
                                    TargetCC, Flag);</div>
                                  <div> }</div>
                                  <div> else {</div>
                                  <div>    // else generate library call</div>
                                  <div>   DAG.getTargetLoweringInfo().s<wbr>oftenSetCCOperands(DAG,
                                    MVT::f32, LHS, RHS,</div>
                                  <div>                                 
                                                     CC, dl);</div>
                                  <div><br>
                                  </div>
                                  <div>   SDValue Flag =
                                    DAG.getNode(XXXISD::CMP, dl,
                                    MVT::Glue, LHS, RHS);</div>
                                  <div><br>
                                  </div>
                                  <div>   if (!RHS.getNode()) {</div>
                                  <div>     RHS = DAG.getConstant(0, dl,
                                    LHS.getValueType());</div>
                                  <div>     TargetCC =
                                    DAG.getConstant(XXXCC::COND_NE<wbr>,
                                    dl, MVT::i8);</div>
                                  <div>   }</div>
                                  <div>   return
                                    DAG.getNode(XXXISD::BR_CC, dl,
                                    MVT::Other,</div>
                                  <div>                  Chain, Dest,
                                    TargetCC, Flag);</div>
                                  <div> }</div>
                                  <div><br>
                                  </div>
                                  <div> and code for getFPCCtoXXCC() is
                                    as following:</div>
                                  <div><br>
                                  </div>
                                  <div> static void
                                    getFPCCtoXXCC(ISD::CondCode CC,
                                    XXXCC::CondCodes &CondCode) {</div>
                                  <div>  switch (CC) {</div>
                                  <div>    default:</div>
                                  <div>      llvm_unreachable("Unknown
                                    FP condition!");</div>
                                  <div>    case ISD::SETEQ:</div>
                                  <div>    case ISD::SETOEQ:</div>
                                  <div>      CondCode = XXXCC::COND_E;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETGT:</div>
                                  <div>    case ISD::SETOGT:</div>
                                  <div>      CondCode = XXXCC::COND_GT;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETGE:</div>
                                  <div>    case ISD::SETOGE:</div>
                                  <div>      CondCode = XXXCC::COND_GE;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETOLT:</div>
                                  <div>    case ISD::SETLT:</div>
                                  <div>      CondCode = XXXCC::COND_LT;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETOLE:</div>
                                  <div>    case ISD::SETLE:</div>
                                  <div>      CondCode = XXXCC::COND_LE;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETONE:</div>
                                  <div>    case ISD::SETNE:</div>
                                  <div>      CondCode = XXXCC::COND_NE;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETUO:</div>
                                  <div>      CondCode = XXXCC::COND_UN;</div>
                                  <div>      break;</div>
                                  <div>    case ISD::SETO:</div>
                                  <div>    case ISD::SETUEQ:</div>
                                  <div>    case ISD::SETUGT:</div>
                                  <div>    case ISD::SETUGE:</div>
                                  <div>    case ISD::SETULT:</div>
                                  <div>    case ISD::SETULE:</div>
                                  <div>    case ISD::SETUNE:</div>
                                  <div>      CC =
                                    getSetCCInverse(CC,false);</div>
                                  <div>      getFPCCtoMBCC(CC,CondCode);</div>
                                  <div>      break;</div>
                                  <div>  }</div>
                                  <div>}</div>
                                  <div><br>
                                  </div>
                                  <div> I am generating wrong code when
                                    using floating point library call
                                    for </div>
                                  <div>comparions. For the following
                                    simple case:</div>
                                  <div>float branchTest(float a, float
                                    b) {</div>
                                  <div><span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>float
                                    retVal;<span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">        </span></div>
                                  <div><span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>if
                                    (a == b) {<span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">     </span></div>
                                  <div><span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">              </span>retVal
                                    = a / b + 22.34;</div>
                                  <div><span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>}</div>
                                  <div><span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>return
                                    retVal;</div>
                                  <div>}</div>
                                  <div>I am getting:</div>
                                  <div>brlid<span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>r15,__nesf2</div>
                                  <div>nop</div>
                                  <div>beqi<span class="m_7239601225858991101m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>r3,.LBB0_2
                                    ; r3 is return regsiter</div>
                                  <div><br>
                                  </div>
                                  <div>Now I want to understand
                                    difference between three different
                                    version of Condition</div>
                                  <div>Codes for same operation and how
                                    according to my target I should
                                    handle them.</div>
                                  <div>For example let's consider SETNE,
                                    SETONE and SETUNE so for my
                                    architecture </div>
                                  <div>I think for floating point all
                                    three are same</div>
                                </div>
                              </blockquote>
                              <br>
                            </div>
                          </div>
                          No, they're not the same. Please see:<br>
                          <br>
                            <a moz-do-not-send="true"
                            class="m_7239601225858991101m_-2662977842983796072moz-txt-link-freetext"
href="http://llvm.org/docs/LangRef.html#id290" target="_blank">http://llvm.org/docs/LangRef.h<wbr>tml#id290</a><br>
                          <br>
                          which explains the difference between SETONE
                          (one) and SETUNE (une). Regarding how SETNE is
                          interpreted for FP, see the comment in the
                          definition of CondCode in
                          include/llvm/CodeGen/ISDOpcode<wbr>s.h which
                          explains, "// Don't care operations: undefined
                          if the input is a nan.".<br>
                          <br>
                          To support the unordered comparisons, if your
                          FPU has only ordered comparisons, then you
                          might need to do the underlying comparison,
                          and a NaN check, and then OR the results. I
                          think that using setCondCodeAction will cause
                          the expansions for the hardware-unsupported
                          variants to happen for you.<br>
                          <br>
                           -Hal<br>
                        </div>
                      </blockquote>
                      <div> </div>
                    </div>
                  </div>
                  <div>Thanks Hal for the guidance !</div>
                  <span class="HOEnZb"><font color="#888888">
                      <div><br>
                      </div>
                      <div>-Vivek </div>
                    </font></span>
                  <div>
                    <div class="h5">
                      <blockquote class="gmail_quote" style="margin:0 0
                        0 .8ex;border-left:1px #ccc
                        solid;padding-left:1ex">
                        <div bgcolor="#FFFFFF" text="#000000"> <br>
                          <blockquote type="cite"><span>
                              <div dir="ltr">
                                <div> so do I need to use </div>
                                <div>getSetCCInverse() ? Also when I
                                  look at the code of </div>
                                <div>TargetLowering::softenSetCCOpe<wbr>rands
                                  I see that for some condition code it
                                  uses</div>
                                <div>getSetCCInverse() and also I am not
                                  able to understand the way it groups </div>
                                <div>condition code in switch case for
                                  example :</div>
                                <div>  case ISD::SETEQ:</div>
                                <div>  case ISD::SETOEQ:</div>
                                <div>    LC1 = (VT == MVT::f32) ?
                                  RTLIB::OEQ_F32 :</div>
                                <div>          (VT == MVT::f64) ?
                                  RTLIB::OEQ_F64 : RTLIB::OEQ_F128;</div>
                                <div>    break;</div>
                                <div>  case ISD::SETNE:</div>
                                <div>  case ISD::SETUNE:</div>
                                <div>    LC1 = (VT == MVT::f32) ?
                                  RTLIB::UNE_F32 :</div>
                                <div>          (VT == MVT::f64) ?
                                  RTLIB::UNE_F64 : RTLIB::UNE_F128;</div>
                                <div>    break;</div>
                                <div>here why SETNE and SETUNE is
                                  considered same, why SETONE is
                                  considered </div>
                                <div>differently. Is there any guideline
                                  to lower conditional code properly?</div>
                                <div><br>
                                </div>
                                <div>Sincerely,</div>
                                <div>Vivek</div>
                                <div><br>
                                </div>
                              </div>
                              <br>
                              <fieldset
                                class="m_7239601225858991101m_-2662977842983796072mimeAttachmentHeader"></fieldset>
                              <br>
                            </span>
                            <pre>______________________________<wbr>_________________
LLVM Developers mailing list
<a moz-do-not-send="true" class="m_7239601225858991101m_-2662977842983796072moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a moz-do-not-send="true" class="m_7239601225858991101m_-2662977842983796072moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><span class="m_7239601225858991101HOEnZb"><font color="#888888">
</font></span></pre><span class="m_7239601225858991101HOEnZb"><font color="#888888">
    </font></span></blockquote><span class="m_7239601225858991101HOEnZb"><font color="#888888">
    

    <pre class="m_7239601225858991101m_-2662977842983796072moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </font></span></div>

</blockquote></div></div></div>
</div></div>
</blockquote></div>
</div>



</blockquote>
<pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre></body></html>