[llvm-commits] PATCH: Initial patches for changing the semantics of llvm.cttz and llvm.ctlz

Chandler Carruth chandlerc at gmail.com
Thu Dec 1 02:47:26 PST 2011


A while back Owen helped me track down a performance problem I had with
some very hot encoding and decoding routines to the different semantics
LLVM uses for '__builtin_ctz' and '__builtin_clz' compared to GCC.
Specifically, GCC doesn't provide a defined result for an input of zero and
LLVM does. On X86, this results in significantly worse code if the user has
already ensured that a zero input will be caught elsewhere.

Owen asked Chris if we could just switch LLVM's intrinsics to the narrower
definition, and he was good with it. The idea was to also fix their naming
to agree more with the common mnemonics and the builtins. Thus, my plan to
resolve this is as follows:

1) introduce new intrinsics 'llvm.ctz' and 'llvm.clz' which will have the
desired new semantics (eventually)
2) teach codegen to treat these as *exactly* the same as the existing
3) teach the rest of LLVM to treat them as aliases for the originals (now
that they will be codegenned correctly)
4) switch frontends to use the new names when the new semantics are
5) add auto-upgrade logic to convert the old intrinsics in IR to the new
ones plus an explicit test for zero
6) switch the LLVM documentation to talk only about the new ones, and their
new semantics
6b) add release notes about this somewhere?
7) remove all support (other than auto-upgrade) for the old intrinsics
8) change the middle end optimizers and codegen of the new intrinsics to
take advantage of the new, narrower semantics
9) profit!!!

Sound like a good plan of attack? I've attached the patches for 1, 2, and
3; these were highly mechanical. Let me know if I can switch to post-commit
review for this at any point, and/or if there are particular steps that
should get extra close review or a announcement.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111201/082b3842/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Begin-introducing-new-intrinsics-which-provide-more-.patch
Type: text/x-patch
Size: 5989 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111201/082b3842/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Teach-codegen-about-the-new-ctz-and-clz-intrinsics.-.patch
Type: text/x-patch
Size: 10038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111201/082b3842/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Now-that-the-backend-treats-ctz-and-clz-LLVM-intrins.patch
Type: text/x-patch
Size: 12032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111201/082b3842/attachment-0002.bin>

More information about the llvm-commits mailing list