[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
Simon Pilgrim via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 21 04:14:53 PDT 2020
RKSimon created this revision.
RKSimon added reviewers: rsmith, craig.topper, spatel.
Herald added a project: clang.
RKSimon requested review of this revision.
This enables us to use the __builtin_bitreverse 8/16/32/64 intrinsics inside constexpr code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86339
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/constant-builtins-2.c
Index: clang/test/Sema/constant-builtins-2.c
===================================================================
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -169,6 +169,11 @@
char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
+char bitreverse1[__builtin_bitreverse8(0x01) == 0x80 ? 1 : -1];
+char bitreverse2[__builtin_bitreverse16(0x3C48) == 0x123C ? 1 : -1];
+char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
+char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 0xF7B3D591E6A2C480 ? 1 : -1];
+
char ffs1[__builtin_ffs(0) == 0 ? 1 : -1];
char ffs2[__builtin_ffs(1) == 1 ? 1 : -1];
char ffs3[__builtin_ffs(0xfbe71) == 1 ? 1 : -1];
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11180,6 +11180,17 @@
return Success(AlignedVal, E);
}
+ case Builtin::BI__builtin_bitreverse8:
+ case Builtin::BI__builtin_bitreverse16:
+ case Builtin::BI__builtin_bitreverse32:
+ case Builtin::BI__builtin_bitreverse64: {
+ APSInt Val;
+ if (!EvaluateInteger(E->getArg(0), Val, Info))
+ return false;
+
+ return Success(Val.reverseBits(), E);
+ }
+
case Builtin::BI__builtin_bswap16:
case Builtin::BI__builtin_bswap32:
case Builtin::BI__builtin_bswap64: {
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -56,7 +56,9 @@
Non-comprehensive list of changes in this release
-------------------------------------------------
-- ...
+- The builtin intrinsics ``__builtin_bitreverse8``, ``__builtin_bitreverse``,
+ ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used
+ within constexpr expressions.
New Compiler Flags
------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86339.286999.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200821/981ae1b6/attachment.bin>
More information about the cfe-commits
mailing list