<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 02/25/2017 03:06 AM, vivek pandya
via llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAHYgpo+jJ+1cfsH=p7cFGb29ODwEnp46Scx8XHQOY_T6CYb5fQ@mail.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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">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">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">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">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().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_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="gmail-Apple-tab-span" style="white-space:pre"> </span>float
retVal;<span class="gmail-Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>if
(a == b) {<span class="gmail-Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>retVal
= a / b + 22.34;</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>}</div>
<div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>return
retVal;</div>
<div>}</div>
<div>I am getting:</div>
<div>brlid<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>r15,__nesf2</div>
<div>nop</div>
<div>beqi<span class="gmail-Apple-tab-span" style="white-space:pre"> </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>
No, they're not the same. Please see:<br>
<br>
<a class="moz-txt-link-freetext" href="http://llvm.org/docs/LangRef.html#id290">http://llvm.org/docs/LangRef.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/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>
<br>
<blockquote
cite="mid:CAHYgpo+jJ+1cfsH=p7cFGb29ODwEnp46Scx8XHQOY_T6CYb5fQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div> so do I need to use </div>
<div>getSetCCInverse() ? Also when I look at the code of </div>
<div>TargetLowering::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="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>