<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="">The ‘makeLibCall' function will definitely be useful for my needs. In connection with the rest of your message, I have identified at least a couple of improvements that I think would benefit the MSP430 target, and possibly the AVR too. In view of that I would be happy to become an occasional patch submitter, but this demands some discipline, such as proper versioning and thorough test case implementation, and unfortunately I do not currently have all the time that this would need. In any case, as I get my own target into completion I may find time in the future to submit what I learned for the benefit of the other targets.<div class=""><div class=""><br class=""></div><div class="">John </div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Jun 2019, at 00:54, Eli Friedman <<a href="mailto:efriedma@quicinc.com" class="">efriedma@quicinc.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Your English is fine, I think. Reading your reply, I didn’t really provide enough context.<o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">There’s a straightforward API for generating libcalls which is usable in custom lowering: TargetLowering::makeLibCall. <o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">By “out of tree targets”, I mean targets which are maintained outside of the<span class="Apple-converted-space"> </span><a href="http://llvm.org/" style="color: purple; text-decoration: underline;" class="">llvm.org</a><span class="Apple-converted-space"> </span>infrastructure (whether or not they’re open-source). The developer policy (<a href="http://llvm.org/docs/DeveloperPolicy.html#test-cases" style="color: purple; text-decoration: underline;" class="">http://llvm.org/docs/DeveloperPolicy.html</a>) says all features must be tested; there’s no reasonable way to test a feature that isn’t actually used by any target in the<span class="Apple-converted-space"> </span><a href="http://llvm.org/" style="color: purple; text-decoration: underline;" class="">llvm.org</a><span class="Apple-converted-space"> </span>tree. So we can’t accept any features unless they benefit at least one in-tree target. So if, for example, AVR would benefit from an improvement to common infrastructure here, that would be fine. If it would only benefit some target you’re working on privately, we have to reject that patch.<o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">It’s possible there’s some infrastructure improvement that would benefit targets like AVR. Changing ConvertNodeToLibcall by itself doesn’t seem to fall into that category; like you’ve noted, nothing would really use it on its own. Maybe it makes sense to change the LowerOperation API? I’m not sure what exactly that would look like, though.<o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">-Eli<o:p class=""></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0in 0in 0in 4pt;" class=""><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Joan Lluch <<a href="mailto:joan.lluch@icloud.com" class="">joan.lluch@icloud.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Tuesday, June 11, 2019 12:27 AM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Eli Friedman <<a href="mailto:efriedma@quicinc.com" class="">efriedma@quicinc.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>[EXT] Re: [llvm-dev] Bug: Library functions for ISD::SRA, ISD::SHL, and ISD::SRL<o:p class=""></o:p></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi Eli,<o:p class=""></o:p></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">First of all, please I would appreciate that you try to not confuse my limited use of English with stupidity or lack or criteria in other subjects. I’m not English native, so please keep that in mind. You have been significantly helpful in the recent past so please keep on.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Interestingly, you made a mention of a related but not identical issue. It is true that most (or all) processors support constant shift instructions so that LLVM can safely assume that<i class="">constant</i><span class="Apple-converted-space"> </span>shifts are legal. I don’t think that LLVM makes any explicit assumption that variable shifts are legal too though, but if it does, then this is not either a problem. <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">We need to make the distinction between constant shifts and variable shifts. The later are generally supported only by the major processors, but not in the general case. In particular the AVR and the MSP430 targets do not have native support for them. In both cases variable shifts are dealt with by means of a custom inserter. This is just a possible way to implement them, but not the easiest or the cleaner one in my opinion.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Another possibility is to implement Custom lower for constant shifts, but to generate a lib call (or an intrinsic) for the variable shifts. The lib call can be generated as part of the Custom lowering, and this is the implementation that I chose for my target, however, the LLVM infrastructure does not make this particularly straightforward for two reasons: <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">- First, there’s no working support for ‘LibCall’ lowering of shifts, this is broken by the omission of the case statement that I mentioned, <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">- Second, there’s no simple way that I am aware to make LLVM to create a lib call from the Custom lowering implementation; <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I am not going to strongly suggest how to solve this problem, but just to state that there’s an actual problem or at least an oddity on the way that shifts are (or can be) dealt with.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">To me, the first thing we need to do is to actually have LibCall operationActions<span class="Apple-converted-space"> </span><i class="">working</i><span class="Apple-converted-space"> </span>for shifts. This is also as a matter of code consistency if you want, and doing this alone doesn’t break anything: ultimately it’s the responsibility of the target to chose whether it uses it or not.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Additionally, we should specify a way to fall through to LibCall lowering from a Custom lower implementation, if required or requested by the target. For example by providing a public path or a hook to ConvertNodeToLibCall, and/or by making the Custom implementation returning something that is recognised by the SelectionDAGLegalize code as a request for a LibCall fall through. Currently, the fall through mechanism after Custom lowering goes directly to the Expand code<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Yet another approach would be that LLVM would explicitly made a distinction between constant and variable shifts, so that they can be lowered in separated ways, but I rather prefer the approach above because it’s more generic and it would widen the custom lowering implementation possibilities for targets with partial support of LLVM instructions.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">In my opinion, it’s not right to consider any "out of tree targets", (whatever that means) as not worth for LLVM improvement. The LLVM project has traditionally focused on major processors for a good reason, but the grow of the IoT and the recent popularisation of many 8 and 16 bit architectures for embedded and control applications make it worth a LLVM focus shift to the particular needs of these smaller processors. Incidentally, the AVR and the MSP430 still remain as ‘experimental’ targets.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Just my two cents anyway, and sorry for my English.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">John Lluch<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div class=""><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On 11 Jun 2019, at 02:16, Eli Friedman <<a href="mailto:efriedma@quicinc.com" style="color: purple; text-decoration: underline;" class="">efriedma@quicinc.com</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">The legalization itself is simple; the issue all the places that assume shifts are legal. For example, you probably don’t want “a+a” to become a libcall.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">-Eli<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0in 0in 0in 4pt;" class=""><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="apple-converted-space"> </span>Joan Lluch <<a href="mailto:joan.lluch@icloud.com" style="color: purple; text-decoration: underline;" class="">joan.lluch@icloud.com</a>><span class="apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="apple-converted-space"> </span>Monday, June 10, 2019 3:05 PM<br class=""><b class="">To:</b><span class="apple-converted-space"> </span>Eli Friedman <<a href="mailto:efriedma@quicinc.com" style="color: purple; text-decoration: underline;" class="">efriedma@quicinc.com</a>><br class=""><b class="">Cc:</b><span class="apple-converted-space"> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color: purple; text-decoration: underline;" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Subject:</b><span class="apple-converted-space"> </span>[EXT] Re: [llvm-dev] Bug: Library functions for ISD::SRA, ISD::SHL, and ISD::SRL<o:p class=""></o:p></div></div></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi Eli,<o:p class=""></o:p></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks for pointing to the CTLZ_ZERO_UNDEF “LibCall” implementation. I have not it in the version that I am currently using, so it’s nice to know that it’s implemented now. <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Incidentally, the CTLZ… implementation is IDENTICAL to what I am proposing for the Shifts. This is not just adding support for “out-of-tree-targets”, but giving consistency to the fact that we have perfectly defined LibCalls for Shifts, but they can’t be used because there’s an omission in the sources.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I only proposed to add a missing case statement to the ConvertNodeToLibCall.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">To my understanding this is totally harmless to any existing or future targets because all what it does is to call the Library function when setOperationAction is set to “LibCall”. This is not different that any other case, and you just confirmed that you added the same for the CTLZ… functions. So I do not understand what you mean by “terrible quality in a lot of cases”: Targets with native shift support are not affected, and neither are targets with custom lowering.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I would suggest that you look in more detail at the actual implementation of the ConvertNodeToLibCall and from where it is called and its actual purpose. There’s nothing else required. So I would appreciate that you elaborate on why you think that this is not a good idea.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks,<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">John Lluch<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div class=""><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On 10 Jun 2019, at 21:09, Eli Friedman <<a href="mailto:efriedma@quicinc.com" style="color: purple; text-decoration: underline;" class=""><span style="color: purple;" class="">efriedma@quicinc.com</span></a>> wrote:<o:p class=""></o:p></div></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">All in-tree targets have variable shift instructions for native integer types, except for AVR. And AVR implements custom lowering. I’m not sure what else would be required to actually make marking a shift as “libcall” actually work well; technically, the change you’re proposing might produce valid code, but it would be terrible quality in a lot of cases. So I’m not eager to add partial support just for out-of-tree targets.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Marking CTLZ_ZERO_UNDEF as “LibCall” was implemented in<span class="apple-converted-space"> </span><a href="https://reviews.llvm.org/D47917" style="color: purple; text-decoration: underline;" class=""><span style="color: rgb(149, 79, 114);" class="">https://reviews.llvm.org/D47917</span></a><span class="apple-converted-space"> </span>. Probably straightforward to extend that to cover CTTZ_ZERO_UNDEF and CTPOP.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">-Eli<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div style="border-style: none none none solid; border-left-width: 1.5pt; border-left-color: blue; padding: 0in 0in 0in 4pt;" class=""><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="apple-converted-space"> </span>llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" style="color: purple; text-decoration: underline;" class=""><span style="color: purple;" class="">llvm-dev-bounces@lists.llvm.org</span></a>><span class="apple-converted-space"> </span><b class="">On Behalf Of<span class="apple-converted-space"> </span></b>Joan Lluch via llvm-dev<br class=""><b class="">Sent:</b><span class="apple-converted-space"> </span>Monday, June 10, 2019 8:31 AM<br class=""><b class="">To:</b><span class="apple-converted-space"> </span>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color: purple; text-decoration: underline;" class=""><span style="color: purple;" class="">llvm-dev@lists.llvm.org</span></a>><br class=""><b class="">Subject:</b><span class="apple-converted-space"> </span>[EXT] [llvm-dev] Bug: Library functions for ISD::SRA, ISD::SHL, and ISD::SRL<o:p class=""></o:p></div></div></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">LLVM appears to support Library functions for <span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ISD</span><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">::<span style="color: rgb(49, 89, 93);" class="">SRA </span></span>,<span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ISD</span><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">::<span style="color: rgb(49, 89, 93);" class="">SHL</span></span>, and <span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ISD</span><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">::<span style="color: rgb(49, 89, 93);" class="">SRL</span></span>, as they are properly defined in RuntimeLibCalls.def.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">The library functions defined in RuntimeLibCalls.def (among others) are these:<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class="">HANDLE_LIBCALL(SRA_I16, "__ashrhi3")</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class="">HANDLE_LIBCALL(SRA_I32, "__ashrsi3")</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class="">HANDLE_LIBCALL(SRA_I64, "__ashrdi3")</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">However, setting<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(49, 89, 93);" class="">setOperationAction</span><span style="font-size: 8.5pt; font-family: Monaco, serif;" class="">(<span style="color: rgb(79, 129, 135);" class="">ISD</span>::<span style="color: rgb(49, 89, 93);" class="">SRA</span>, <span style="color: rgb(79, 129, 135);" class="">MVT</span>::<span style="color: rgb(49, 89, 93);" class="">i16</span>, <span style="color: rgb(49, 89, 93);" class="">LibCall</span>);</span><o:p class=""></o:p></div></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">in the TargetLowering constructor causes LLVM to stop with an assert as the shift instruction can’t be selected. <o:p class=""></o:p></div></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">The problem is in <span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">SelectionDAGLegalize</span><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">::ConvertNodeToLibcall </span>because there’s no switch case for any of the Shift instructions. <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">The problem gets solved by just adding switch cases like this (and similar for the other shift instructions):<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(186, 45, 162);" class="">case</span><span class="apple-converted-space"><span style="font-size: 8.5pt; font-family: Monaco, serif;" class=""> </span></span><span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135);" class="">ISD</span><span style="font-size: 8.5pt; font-family: Monaco, serif;" class="">::<span style="color: rgb(49, 89, 93);" class="">SRA</span>:</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class=""> Results.<span style="color: rgb(49, 89, 93);" class="">push_back</span>(<span style="color: rgb(49, 89, 93);" class="">ExpandIntLibCall</span>(Node,<span class="apple-converted-space"> </span><span style="color: rgb(186, 45, 162);" class="">false</span>,</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class=""> <span class="apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">RTLIB</span>::<span style="color: rgb(49, 89, 93);" class="">SRA_I16</span>,</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif;" class=""> <span class="apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">RTLIB</span>::<span style="color: rgb(49, 89, 93);" class="">SRA_I16</span>,<span class="apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">RTLIB</span>::<span style="color: rgb(49, 89, 93);" class="">SRA_I32</span>,</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class=""> <span style="color: rgb(79, 129, 135);" class="">RTLIB</span>::<span style="color: rgb(49, 89, 93);" class="">SRA_I64</span>,<span class="apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">RTLIB</span>::<span style="color: rgb(49, 89, 93);" class="">SRA_I128</span>));</span><o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I think this is a BUG by omission of necessary switch cases.<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Similarly, the following ISD codes <span style="font-size: 8.5pt; font-family: Monaco, serif; color: rgb(79, 129, 135); background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">ISD</span><span style="font-size: 8.5pt; font-family: Monaco, serif; background-color: white; background-position: initial initial; background-repeat: initial initial;" class="">::<span style="color: rgb(49, 89, 93);" class="">CTTZ, </span><span style="color: rgb(79, 129, 135);" class="">ISD</span>::<span style="color: rgb(49, 89, 93);" class="">CTLZ, </span><span style="color: rgb(79, 129, 135);" class="">ISD</span>::<span style="color: rgb(49, 89, 93);" class="">CTPOP </span></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.<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" 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. <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Instead, LLVM should have them available as possible LibCalls.<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Any comments or opinions on these subjects are appreciated<o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></div></div></div><div class=""><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Joan Lluch</div></div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div><br class=""></div></div></body></html>