[CodeGen] add/fix rotate builtins that map to LLVM funnel shift (retry)
authorSanjay Patel <spatel@rotateright.com>
Sun, 19 Aug 2018 14:44:47 +0000 (14:44 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 19 Aug 2018 14:44:47 +0000 (14:44 +0000)
commit446529b0d9452e3d4d6164f48ce2ccb104cdd6a5
tree2a304018245f41f376f2cc642a914803b8230d6d
parent39b4dd2da7120901b1295634dfd0b457c8c173e0
[CodeGen] add/fix rotate builtins that map to LLVM funnel shift (retry)

This is a retry of rL340135 (reverted at rL340136 because of gcc host compiler crashing)
with 2 changes:
1. Move the code into a helper to reduce code duplication (and hopefully work-around the crash).
2. The original commit had a formatting bug in the docs (missing an underscore).

Original commit message:

This exposes the LLVM funnel shift intrinsics as more familiar bit rotation functions in clang
(when both halves of a funnel shift are the same value, it's a rotate).

We're free to name these as we want because we're not copying gcc, but if there's some other
existing art (eg, the microsoft ops that are modified in this patch) that we want to replicate,
we can change the names.

The funnel shift intrinsics were added here:
https://reviews.llvm.org/D49242

With improved codegen in:
https://reviews.llvm.org/rL337966
https://reviews.llvm.org/rL339359

And basic IR optimization added in:
https://reviews.llvm.org/rL338218
https://reviews.llvm.org/rL340022

...so these are expected to produce asm output that's equal or better to the multi-instruction
alternatives using primitive C/IR ops.

In the motivating loop example from PR37387:
https://bugs.llvm.org/show_bug.cgi?id=37387#c7
...we get the expected 'rolq' x86 instructions if we substitute the rotate builtin into the source.

Differential Revision: https://reviews.llvm.org/D50924

llvm-svn: 340137
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGen/builtin-rotate.c [new file with mode: 0644]
clang/test/CodeGen/ms-intrinsics-rotations.c