[llvm-dev] Bug: Library functions for ISD::SRA, ISD::SHL, and ISD::SRL

Joan Lluch via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 10 08:30:39 PDT 2019


LLVM appears to support Library functions for ISD::SRA ,ISD::SHL, and ISD::SRL, as they are properly defined in RuntimeLibCalls.def.

The library functions defined in RuntimeLibCalls.def (among others) are these:

HANDLE_LIBCALL(SRA_I16, "__ashrhi3")
HANDLE_LIBCALL(SRA_I32, "__ashrsi3")
HANDLE_LIBCALL(SRA_I64, "__ashrdi3")

However, setting

setOperationAction(ISD::SRA, MVT::i16, LibCall);

in the TargetLowering constructor causes LLVM to stop with an assert as the shift instruction can’t be selected. 

The problem is in SelectionDAGLegalize::ConvertNodeToLibcall because there’s no switch case for any of the Shift instructions. 

The problem gets solved by just adding switch cases like this (and similar for the other shift instructions):

case ISD::SRA:
      Results.push_back(ExpandIntLibCall(Node, false,
                                       RTLIB::SRA_I16,
                                       RTLIB::SRA_I16, RTLIB::SRA_I32,
                                       RTLIB::SRA_I64, RTLIB::SRA_I128));

I think this is a BUG by omission of necessary switch cases.

 
Similarly, the following ISD codes  ISD::CTTZ, ISD::CTLZ, ISD::CTPOP 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.
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. 
Instead, LLVM should have them available as possible LibCalls.

Any comments or opinions on these subjects are appreciated

Joan Lluch

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190610/38ae307b/attachment.html>


More information about the llvm-dev mailing list