Author: Simon Pilgrim Date: 2020-08-23T16:11:58+01:00 New Revision: a1dc3d241ba00042b6160287f887d1019e36bae0
URL: https://github.com/llvm/llvm-project/commit/a1dc3d241ba00042b6160287f887d1019e36bae0 DIFF: https://github.com/llvm/llvm-project/commit/a1dc3d241ba00042b6160287f887d1019e36bae0.diff LOG: [X86] Enable constexpr on ROTL/ROTR intrinsics (PR31446) This enables constexpr rotate intrinsics defined in ia32intrin.h, including the MS specific builtins. Added: Modified: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/lib/AST/ExprConstant.cpp clang/lib/Headers/ia32intrin.h clang/test/CodeGen/rot-intrinsics.c Removed: ################################################################################ diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 970c75ffafee..c89f924c58ba 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -3675,4 +3675,18 @@ The following x86-specific intrinsics can be used in constant expressions: * ``_popcnt32`` * ``_popcnt64`` * ``__popcntd`` -* ``__popcntq`` \ No newline at end of file +* ``__popcntq`` +* ``__rolb`` +* ``__rolw`` +* ``__rold`` +* ``__rolq`` +* ``__rorb`` +* ``__rorw`` +* ``__rord`` +* ``__rorq`` +* ``_rotl`` +* ``_rotr`` +* ``_rotwl`` +* ``_rotwr`` +* ``_lrotl`` +* ``_lrotr`` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b4e594a1c4b4..c036f66d60bf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -182,6 +182,12 @@ X86 Support in Clang - The x86 intrinsics ``_castf32_u32``, ``_castf64_u64``, ``_castu32_f32`` and ``_castu64_f64`` may now be used within constant expressions. +- The x86 intrinsics ``__rolb``, ``__rolw``, ``__rold``, ``__rolq`, ``_rotl``, + ``_rotwl`` and ``_lrotl`` may now be used within constant expressions. + +- The x86 intrinsics ``__rorb``, ``__rorw``, ``__rord``, ``__rorq`, ``_rotr``, + ``_rotwr`` and ``_lrotr`` may now be used within constant expressions. + Internal API Changes -------------------- diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index c23233ab8c8c..014c48e6f08f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11361,7 +11361,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_rotateleft8: case Builtin::BI__builtin_rotateleft16: case Builtin::BI__builtin_rotateleft32: - case Builtin::BI__builtin_rotateleft64: { + case Builtin::BI__builtin_rotateleft64: + case Builtin::BI_rotl8: // Microsoft variants of rotate right + case Builtin::BI_rotl16: + case Builtin::BI_rotl: + case Builtin::BI_lrotl: + case Builtin::BI_rotl64: { APSInt Val, Amt; if (!EvaluateInteger(E->getArg(0), Val, Info) || !EvaluateInteger(E->getArg(1), Amt, Info)) @@ -11373,7 +11378,12 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_rotateright8: case Builtin::BI__builtin_rotateright16: case Builtin::BI__builtin_rotateright32: - case Builtin::BI__builtin_rotateright64: { + case Builtin::BI__builtin_rotateright64: + case Builtin::BI_rotr8: // Microsoft variants of rotate right + case Builtin::BI_rotr16: + case Builtin::BI_rotr: + case Builtin::BI_lrotr: + case Builtin::BI_rotr64: { APSInt Val, Amt; if (!EvaluateInteger(E->getArg(0), Val, Info) || !EvaluateInteger(E->getArg(1), Amt, Info)) diff --git a/clang/lib/Headers/ia32intrin.h b/clang/lib/Headers/ia32intrin.h index f01a3adfc3b2..00138effd505 100644 --- a/clang/lib/Headers/ia32intrin.h +++ b/clang/lib/Headers/ia32intrin.h @@ -373,43 +373,43 @@ _wbinvd(void) { __builtin_ia32_wbinvd(); } -static __inline__ unsigned char __DEFAULT_FN_ATTRS +static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR __rolb(unsigned char __X, int __C) { return __builtin_rotateleft8(__X, __C); } -static __inline__ unsigned char __DEFAULT_FN_ATTRS +static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR __rorb(unsigned char __X, int __C) { return __builtin_rotateright8(__X, __C); } -static __inline__ unsigned short __DEFAULT_FN_ATTRS +static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR __rolw(unsigned short __X, int __C) { return __builtin_rotateleft16(__X, __C); } -static __inline__ unsigned short __DEFAULT_FN_ATTRS +static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR __rorw(unsigned short __X, int __C) { return __builtin_rotateright16(__X, __C); } -static __inline__ unsigned int __DEFAULT_FN_ATTRS +static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR __rold(unsigned int __X, int __C) { return __builtin_rotateleft32(__X, __C); } -static __inline__ unsigned int __DEFAULT_FN_ATTRS +static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR __rord(unsigned int __X, int __C) { return __builtin_rotateright32(__X, __C); } #ifdef __x86_64__ -static __inline__ unsigned long long __DEFAULT_FN_ATTRS +static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR __rolq(unsigned long long __X, int __C) { return __builtin_rotateleft64(__X, __C); } -static __inline__ unsigned long long __DEFAULT_FN_ATTRS +static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR __rorq(unsigned long long __X, int __C) { return __builtin_rotateright64(__X, __C); } diff --git a/clang/test/CodeGen/rot-intrinsics.c b/clang/test/CodeGen/rot-intrinsics.c index dcdc54c4585a..f8c78119a1c4 100644 --- a/clang/test/CodeGen/rot-intrinsics.c +++ b/clang/test/CodeGen/rot-intrinsics.c @@ -1,28 +1,35 @@ -// RUN: %clang_cc1 -ffreestanding -triple i686--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG -// RUN: %clang_cc1 -ffreestanding -triple x86_64--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG -// RUN: %clang_cc1 -fms-extensions -fms-compatibility -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG -// RUN: %clang_cc1 -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG -// RUN: %clang_cc1 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG -// RUN: %clang_cc1 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c -ffreestanding -triple i686--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c -ffreestanding -triple x86_64--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG +// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG + +// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding -triple i686--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding -triple x86_64--linux -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG +// RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=i686-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG +// RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG #include <x86intrin.h> unsigned char test__rolb(unsigned char value, int shift) { -// CHECK-LABEL: i8 @test__rolb +// CHECK-LABEL: test__rolb // CHECK: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]]) // CHECK: ret i8 [[R]] return __rolb(value, shift); } unsigned short test__rolw(unsigned short value, int shift) { -// CHECK-LABEL: i16 @test__rolw +// CHECK-LABEL: test__rolw // CHECK: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]]) // CHECK: ret i16 [[R]] return __rolw(value, shift); } unsigned int test__rold(unsigned int value, int shift) { -// CHECK-LABEL: i32 @test__rold +// CHECK-LABEL: test__rold // CHECK: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK: ret i32 [[R]] return __rold(value, shift); @@ -30,7 +37,7 @@ unsigned int test__rold(unsigned int value, int shift) { #if defined(__x86_64__) unsigned long test__rolq(unsigned long value, int shift) { -// CHECK-LONG-LABEL: i64 @test__rolq +// CHECK-LONG-LABEL: test__rolq // CHECK-LONG: [[R:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]]) // CHECK-LONG: ret i64 [[R]] return __rolq(value, shift); @@ -38,21 +45,21 @@ unsigned long test__rolq(unsigned long value, int shift) { #endif unsigned char test__rorb(unsigned char value, int shift) { -// CHECK-LABEL: i8 @test__rorb +// CHECK-LABEL: test__rorb // CHECK: [[R:%.*]] = call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]]) // CHECK: ret i8 [[R]] return __rorb(value, shift); } unsigned short test__rorw(unsigned short value, int shift) { -// CHECK-LABEL: i16 @test__rorw +// CHECK-LABEL: test__rorw // CHECK: [[R:%.*]] = call i16 @llvm.fshr.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]]) // CHECK: ret i16 [[R]] return __rorw(value, shift); } unsigned int test__rord(unsigned int value, int shift) { -// CHECK-LABEL: i32 @test__rord +// CHECK-LABEL: test__rord // CHECK: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK: ret i32 [[R]] return __rord(value, shift); @@ -60,7 +67,7 @@ unsigned int test__rord(unsigned int value, int shift) { #if defined(__x86_64__) unsigned long test__rorq(unsigned long value, int shift) { -// CHECK-LONG-LABEL: i64 @test__rorq +// CHECK-LONG-LABEL: test__rorq // CHECK-LONG: [[R:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]]) // CHECK-LONG: ret i64 [[R]] return __rorq(value, shift); @@ -68,25 +75,25 @@ unsigned long test__rorq(unsigned long value, int shift) { #endif unsigned short test_rotwl(unsigned short value, int shift) { -// CHECK-LABEL: i16 @test_rotwl +// CHECK-LABEL: test_rotwl // CHECK: [[R:%.*]] = call i16 @llvm.fshl.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]]) // CHECK: ret i16 [[R]] return _rotwl(value, shift); } unsigned int test_rotl(unsigned int value, int shift) { -// CHECK-LABEL: i32 @test_rotl +// CHECK-LABEL: test_rotl // CHECK: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK: ret i32 [[R]] return _rotl(value, shift); } unsigned long test_lrotl(unsigned long value, int shift) { -// CHECK-32BIT-LONG-LABEL: i32 @test_lrotl +// CHECK-32BIT-LONG-LABEL: test_lrotl // CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK-32BIT-LONG: ret i32 [[R]] // -// CHECK-64BIT-LONG-LABEL: i64 @test_lrotl +// CHECK-64BIT-LONG-LABEL: test_lrotl // CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]]) // CHECK-64BIT-LONG: ret i64 [[R]] return _lrotl(value, shift); @@ -94,27 +101,57 @@ unsigned long test_lrotl(unsigned long value, int shift) { unsigned short test_rotwr(unsigned short value, int shift) { -// CHECK-LABEL: i16 @test_rotwr +// CHECK-LABEL: test_rotwr // CHECK: [[R:%.*]] = call i16 @llvm.fshr.i16(i16 [[X:%.*]], i16 [[X]], i16 [[Y:%.*]]) // CHECK: ret i16 [[R]] return _rotwr(value, shift); } unsigned int test_rotr(unsigned int value, int shift) { -// CHECK-LABEL: i32 @test_rotr +// CHECK-LABEL: test_rotr // CHECK: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK: ret i32 [[R]] return _rotr(value, shift); } unsigned long test_lrotr(unsigned long value, int shift) { -// CHECK-32BIT-LONG-LABEL: i32 @test_lrotr +// CHECK-32BIT-LONG-LABEL: test_lrotr // CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]]) // CHECK-32BIT-LONG: ret i32 [[R]] // -// CHECK-64BIT-LONG-LABEL: i64 @test_lrotr +// CHECK-64BIT-LONG-LABEL: test_lrotr // CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]]) // CHECK-64BIT-LONG: ret i64 [[R]] return _lrotr(value, shift); } +// Test constexpr handling. +#if defined(__cplusplus) && (__cplusplus >= 201103L) + +char rolb_0[__rolb(0x01, 5) == 0x20 ? 1 : -1]; +char rolw_0[__rolw(0x3210, 11) == 0x8190 ? 1 : -1]; +char rold_0[__rold(0x76543210, 22) == 0x841D950C ? 1 : -1]; + +char rorb_0[__rorb(0x01, 5) == 0x08 ? 1 : -1]; +char rorw_0[__rorw(0x3210, 11) == 0x4206 ? 1 : -1]; +char rord_0[__rord(0x76543210, 22) == 0x50C841D9 ? 1 : -1]; + +#if defined(__x86_64__) +char rolq_0[__rolq(0xFEDCBA9876543210ULL, 55) == 0x087F6E5D4C3B2A19ULL ? 1 : -1]; +char rorq_0[__rorq(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1]; +#endif + +char rotwl_0[_rotwl(0x3210, 4) == 0x2103 ? 1 : -1]; +char rotwr_0[_rotwr(0x3210, 4) == 0x0321 ? 1 : -1]; +char rotl_0[_rotl(0x76543210, 8) == 0x54321076 ? 1 : -1]; +char rotr_0[_rotr(0x76543210, 8) == 0x10765432 ? 1 : -1]; + +#if defined(__LP64__) && !defined(_MSC_VER) +char lrotl_0[_lrotl(0xFEDCBA9876543210ULL, 55) == 0x087F6E5D4C3B2A19ULL ? 1 : -1]; +char lrotr_0[_lrotr(0xFEDCBA9876543210ULL, 55) == 0xB97530ECA86421FDULL ? 1 : -1]; +#else +char lrotl_0[_lrotl(0x76543210, 22) == 0x841D950C ? 1 : -1]; +char lrotr_0[_lrotr(0x76543210, 22) == 0x50C841D9 ? 1 : -1]; +#endif + +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits