<div dir="ltr"><div><div><div>Re-adding llvm-dev.<br><br></div>I think that calling a library routine if a target doesn't have a shift operation is quite reasonable. I'd imagine it would be tricky to transform the SDAG to get the semantics of a shift in a completely target-independent fashion.<br><br></div>The actual libcall likely exists in one of the libraries that ship with LLVM and you'd just have to link with that (I imagine it would be compiler-rt).<br><br></div>Just grepping in there certainly finds it in: projects/compiler-rt/lib/builtins/lshrdi3.c.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 31, 2017 at 2:18 PM, 陳韋任 <span dir="ltr"><<a href="mailto:chenwj.cs97g@g2.nctu.edu.tw" target="_blank">chenwj.cs97g@g2.nctu.edu.tw</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"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi Nemanja,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  Thanks for your input. I get the same conclusion after reading the source code for my particular case.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Yes, the libcall occurred during type legalization. For my case, it's DAGTypeLegalizer::<wbr>ExpandIntRes_Shift [1].</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">If the target doesn't support such case, the type legalizer will try to emit libcall if there is one (TLI.getLibcallName(LC) != nullptr).</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="arial, helvetica, sans-serif">    if (LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC)) {</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">      SDValue Ops[2] = { N->getOperand(0), N->getOperand(1) };</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">      SplitInteger(TLI.makeLibCall(<wbr>DAG, LC, VT, Ops, isSigned, dl).first, Lo, Hi);</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">      return;</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">    }</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">    if (!<wbr>ExpandShiftWithUnknownAmountBi<wbr>t(N, Lo, Hi))</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">      llvm_unreachable("Unsupported shift!");</font></div></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I think either we provide the corresponding libcall in libgcc, or make proper handling elsewhere in the</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">type legalizer.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">[1] <a href="http://llvm.org/doxygen/LegalizeIntegerTypes_8cpp_source.html" target="_blank">http://llvm.org/doxygen/<wbr>LegalizeIntegerTypes_8cpp_<wbr>source.html</a></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">chenwj</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-29 20:41 GMT+08:00 Nemanja Ivanovic <span dir="ltr"><<a href="mailto:nemanja.i.ibm@gmail.com" target="_blank">nemanja.i.ibm@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>If I'm not mistaken, legalization will introduce the libcalls as per the call to `InitLibcallNames()` in `TargetLoweringBase::TargetLow<wbr>eringBase()` (or anything your target overrides). This would seem to imply that your target doesn't have i64 as a legal type (or at the very least, shift-right-logical is not legal for i64 types on your target).<br><br></div>For an example of how this ends up in the code, you can compile a program such as this with triple -mtriple=powerpc64le-unknown-u<wbr>nknown<br>```<br>define ppc_fp128 @test(ppc_fp128 %a, ppc_fp128 %b) {<br>entry:<br>  %add = fadd ppc_fp128 %a, %b<br>  ret ppc_fp128 %add<br>}<br>```<br></div>You can see when the result type of the `fadd` is legalized, a libcall is added to the SDAG (since ppcf128 is not a legal type - no registers on PPC for it).<br><br></div>I hope this helps (and I hope I'm not misleading you here).<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-9222378579071609371h5">On Fri, May 19, 2017 at 9:44 AM, 陳韋任 via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-9222378579071609371h5"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi All,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  I am looking at a linker error under O2:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">    </font><span style="font-family:arial,sans-serif;color:rgb(84,84,84)"> </span><font color="#000000">undefined symbol __lshrdi3</font></div><div class="gmail_default"><font color="#000000"><br></font></div><div class="gmail_default"><font color="#000000">I have two questions here:</font></div><div class="gmail_default"><font color="#000000"><br></font></div><div class="gmail_default"><font color="#000000">  1. Does that mean our libgcc (?) doesn't implement __lshrdi3? Or more generally, why I have</font></div><div class="gmail_default"><font color="#000000">      such linker error?</font></div><div class="gmail_default"><font color="#000000"><br></font></div><div class="gmail_default"><font color="#000000">  2. Seems some operations are combined, and replaced with </font><span style="color:rgb(0,0,0)">__lshrdi3 call. I am interested in</span></div><div class="gmail_default"><span style="color:rgb(0,0,0)">      when such </span><span style="color:rgb(0,0,0)">libcall will be generated? Could you show me one example so that I can trace</span></div><div class="gmail_default"><span style="color:rgb(0,0,0)">      the LLVM source code on my own?</span></div><div class="gmail_default"><span style="color:rgb(0,0,0)"><br></span></div><div class="gmail_default"><span style="color:rgb(0,0,0)">Thanks.</span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">chenwj</div><span class="HOEnZb"><font color="#888888"><span class="m_-9222378579071609371m_4934546985717140022HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_-9222378579071609371m_4934546985717140022m_9200220222238225322gmail_signature"><div dir="ltr"><div>Wei-Ren Chen (陳韋任)<br>Homepage: <a href="https://people.cs.nctu.edu.tw/~chenwj" target="_blank">https://people.cs.nctu.edu.tw/<wbr>~chenwj</a></div></div></div>
</font></span></font></span></div><span class="HOEnZb"><font color="#888888">
<br></font></span></div></div><span class="HOEnZb"><font color="#888888">______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888">
</font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_-9222378579071609371gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Wei-Ren Chen (陳韋任)<br>Homepage: <a href="https://people.cs.nctu.edu.tw/~chenwj" target="_blank">https://people.cs.nctu.edu.tw/<wbr>~chenwj</a></div></div></div>
</font></span></div>
</blockquote></div><br></div>