<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 9, 2017 at 9:35 PM, Hal Finkel <span dir="ltr"><<a 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="h5">
<p><br>
</p>
<div class="m_-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 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 href="http://fcmp.gt" target="_blank">fcmp.gt</a>
--> ordered grater than, if any input NaN then return false</div>
<div><a href="http://fcmp.ne" target="_blank">fcmp.ne</a>
--> ordered not equal, if any input NaN then return true</div>
<div><a 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().<wbr>softenSetCCOperands(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_<wbr>NE, 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_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>float
retVal;<span class="m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span></div>
<div><span class="m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>if
(a == b) {<span class="m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span></div>
<div><span class="m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>retVal
= a / b + 22.34;</div>
<div><span class="m_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>}</div>
<div><span class="m_-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_-2662977842983796072gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>r15,__nesf2</div>
<div>nop</div>
<div>beqi<span class="m_-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 class="m_-2662977842983796072moz-txt-link-freetext" href="http://llvm.org/docs/LangRef.html#id290" target="_blank">http://llvm.org/docs/LangRef.<wbr>html#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/<wbr>ISDOpcodes.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>Thanks Hal for the guidance !</div><div><br></div><div>-Vivek </div><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 class="">
<div dir="ltr">
<div> so do I need to use </div>
<div>getSetCCInverse() ? Also when I look at the code of </div>
<div>TargetLowering::<wbr>softenSetCCOperands 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_-2662977842983796072mimeAttachmentHeader"></fieldset>
<br>
</span><pre>______________________________<wbr>_________________
LLVM Developers mailing list
<a class="m_-2662977842983796072moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a class="m_-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="HOEnZb"><font color="#888888">
</font></span></pre><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
<pre class="m_-2662977842983796072moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</font></span></div>
</blockquote></div><br></div></div>