[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
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 -- 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 -- ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
erichkeane accepted this revision. erichkeane added a comment. This revision is now accepted and ready to land. This looks right to me. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86339/new/ https://reviews.llvm.org/D86339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
rsmith added a comment. Can you also add documentation to LanguageExtensions.rst? Thanks! Comment at: clang/docs/ReleaseNotes.rst:61 + ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used + within constexpr expressions. There's no such thing as a "constexpr expression". The right term is "constant expressions". Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86339/new/ https://reviews.llvm.org/D86339 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D86339: Enable constexpr on BITREVERSE builtin intrinsics (PR47249)
This revision was automatically updated to reflect the committed changes. Closed by commit rGe7d9182a666a: Enable constexpr on BITREVERSE builtin intrinsics (PR47249) (authored by RKSimon). Changed prior to commit: https://reviews.llvm.org/D86339?vs=286999&id=287182#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86339/new/ https://reviews.llvm.org/D86339 Files: clang/docs/LanguageExtensions.rst 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 rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1]; char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1]; char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 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,6 +56,10 @@ Non-comprehensive list of changes in this release - +- The builtin intrinsics ``__builtin_bitreverse8``, ``__builtin_bitreverse16``, + ``__builtin_bitreverse32`` and ``__builtin_bitreverse64`` may now be used + within constant expressions. + - The builtin intrinsics ``__builtin_rotateleft8``, ``__builtin_rotateleft16``, ``__builtin_rotateleft32`` and ``__builtin_rotateleft64`` may now be used within constant expressions. Index: clang/docs/LanguageExtensions.rst === --- clang/docs/LanguageExtensions.rst +++ clang/docs/LanguageExtensions.rst @@ -1984,7 +1984,7 @@ The '``__builtin_bitreverse``' family of builtins is used to reverse the bitpattern of an integer value; for example ``0b10110110`` becomes -``0b01101101``. +``0b01101101``. These builtins can be used within constant expressions. ``__builtin_rotateleft`` 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 rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1]; char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1]; char rotateleft2[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 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