<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">LLVM appears to support Library functions for <span style="color: rgb(79, 129, 135); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(49, 89, 93);" class="">SRA </span>,<span style="color: rgb(79, 129, 135); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(49, 89, 93);" class="">SHL</span>, and <span style="color: rgb(79, 129, 135); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(49, 89, 93);" class="">SRL</span>, as they are properly defined in RuntimeLibCalls.def.<br class=""><div class=""><br class=""></div><div class="">The library functions defined in RuntimeLibCalls.def (among others) are these:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">HANDLE_LIBCALL(SRA_I16, "__ashrhi3")</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">HANDLE_LIBCALL(SRA_I32, "__ashrsi3")</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">HANDLE_LIBCALL(SRA_I64, "__ashrdi3")</div><div class=""><br class=""></div><div class="">However, setting</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class="">setOperationAction<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">ISD</span><span style="color: #000000" class="">::</span>SRA<span style="color: #000000" class="">, </span><span style="color: #4f8187" class="">MVT</span><span style="color: #000000" class="">::</span>i16<span style="color: #000000" class="">, </span>LibCall<span style="color: #000000" class="">);</span></div></div><div class=""><br class=""></div><div class="">in the TargetLowering constructor causes LLVM to stop with an assert as the shift instruction can’t be selected. </div></div><div class=""><br class=""></div><div class="">The problem is in <span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">SelectionDAGLegalize</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::ConvertNodeToLibcall </span>because there’s no switch case for any of the Shift instructions. </div><div class=""><br class=""></div><div class="">The problem gets solved by just adding switch cases like this (and similar for the other shift instructions):</div><div class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">case<span style="color: #000000" class=""> </span><span style="color: #4f8187" class="">ISD</span><span style="color: #000000" class="">::</span><span style="color: #31595d" class="">SRA</span><span style="color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">      Results.</span>push_back<span style="color: #000000" class="">(</span>ExpandIntLibCall<span style="color: #000000" class="">(Node, </span><span style="color: #ba2da2" class="">false</span><span style="color: #000000" class="">,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">                                       <span style="color: #4f8187" class="">RTLIB</span>::<span style="color: #31595d" class="">SRA_I16</span>,</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class="">                                       <span style="color: #4f8187" class="">RTLIB</span>::<span style="color: #31595d" class="">SRA_I16</span>, <span style="color: #4f8187" class="">RTLIB</span>::<span style="color: #31595d" class="">SRA_I32</span>,</div><div class=""><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">                                       </span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">RTLIB</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(49, 89, 93);" class="">SRA_I64</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">, </span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">RTLIB</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(49, 89, 93);" class="">SRA_I128</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">));</span></div><div class=""><br class=""></div><div class="">I think this is a BUG by omission of necessary switch cases.</div><div class=""><br class=""></div><div class=""> </div><div class="">Similarly, the following ISD codes  <span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="color: rgb(49, 89, 93); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">CTTZ, </span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="color: rgb(49, 89, 93); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">CTLZ, </span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">ISD</span><span style="font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">::</span><span style="color: rgb(49, 89, 93); font-family: Monaco; font-size: 11px; background-color: rgb(255, 255, 255);" class="">CTPOP </span>do not define any Library calls, despite LLVM being able to fully expand them into rather large code for targets that do not natively implement them.</div><div class="">I regard this also as an omission/bug, because not all targets would benefit from the custom expansion of these ISD codes, which as said can get unnecessarily long and costly. </div><div class="">Instead, LLVM should have them available as possible LibCalls.</div><div class=""><br class=""></div><div class="">Any comments or opinions on these subjects are appreciated</div><div class=""><br class=""></div><div class="">Joan Lluch</div><div class=""><br class=""></div><div class=""> </div></body></html>