Braden Nelson via llvm-dev
2018-Nov-05 17:57 UTC
[llvm-dev] Extra Bit Manipulation intrinsics?
Would it be worth it to add intrinsics for bitfield extract/deposit and binary rotate left/right? Both of these have dedicated instructions in multiple ISAs, including the two major ISAs (x86-64 and ARM) Adding them could decrease load on the backend to recognize common intrinsic patterns that correspond to these instructions, but could increase load on backends that do not have dedicated instructions for these intrinsics. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181105/b902b5a2/attachment-0001.html>
Hongbin Zheng via llvm-dev
2018-Nov-06 04:45 UTC
[llvm-dev] Extra Bit Manipulation intrinsics?
There used to be such intrinsics (bit-field extract/deposit): http://releases.llvm.org/2.0/docs/LangRef.html#int_part_select http://releases.llvm.org/2.0/docs/LangRef.html#int_part_set But they are removed later. Our internal branch of llvm actual keep them. Depending on how you want to use them, if you mixed them into pointer calculations, it can easily confuse scalar evolution. This is bad. Also, it is not hard to build these intrinsics from patterns of and/or/shift/trunc/zext, so mabe you could build them in the backend instead of at the LLVM IR level. E.g https://github.com/etherzhhb/Shang/blob/eb4aa11385b93af4b73cfd4701e1473124ada325/lib/BitLevelOpt/BitLevelOpt.cpp On Mon, Nov 5, 2018 at 8:25 PM Braden Nelson via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Would it be worth it to add intrinsics for bitfield extract/deposit and > binary rotate left/right? > Both of these have dedicated instructions in multiple ISAs, including the > two major ISAs (x86-64 and ARM) > Adding them could decrease load on the backend to recognize common > intrinsic patterns that correspond to these instructions, but could > increase load on backends that do not have dedicated instructions for these > intrinsics. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181105/1b77b289/attachment.html>
The problem with that is that a bitfield extract of n bits starting at bit b (mask == (1<<b)-1) corresponds to: (X >> b) & mask Replacing it with an intrinsic hides this fact and you have to carefully examine every instcombine rule that operates on an “&” to also operate on the bitfield extract. You need to add a good amount of extra combines and it becomes likely that some get missed. Thus forming such intrinsics before instruction selection in the backend is bad from a software engineering point of view IMO. A similar reasoning can be applied to bitfield insertions. - Matthias> On Nov 5, 2018, at 9:57 AM, Braden Nelson via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Would it be worth it to add intrinsics for bitfield extract/deposit and binary rotate left/right? > Both of these have dedicated instructions in multiple ISAs, including the two major ISAs (x86-64 and ARM) > Adding them could decrease load on the backend to recognize common intrinsic patterns that correspond to these instructions, but could increase load on backends that do not have dedicated instructions for these intrinsics. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Sanjay Patel via llvm-dev
2018-Nov-06 14:13 UTC
[llvm-dev] Extra Bit Manipulation intrinsics?
Rotates are a special case of the recently added funnel shift ops: http://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic We don't canonicalize standard IR (shifts and bitwise logic) to the intrinsics yet, but that is the intent. There are also clang builtins for rotate left/right that map to the funnel shift intrinsics: https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions On Mon, Nov 5, 2018 at 9:25 PM Braden Nelson via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Would it be worth it to add intrinsics for bitfield extract/deposit and > binary rotate left/right? > Both of these have dedicated instructions in multiple ISAs, including the > two major ISAs (x86-64 and ARM) > Adding them could decrease load on the backend to recognize common > intrinsic patterns that correspond to these instructions, but could > increase load on backends that do not have dedicated instructions for these > intrinsics. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181106/352faf77/attachment.html>