Skip to content

Commit 55175c1

Browse files
Bigcheesehyp
authored andcommitted
Revert "Re-fix _lrotl/_lrotr to always take Long, no matter the platform."
This reverts commit 92146ce. This commit broke users targeting LP64 systems that expect these intrinsics to match the MSVC behavior of working on 32 bit integers. These users use a LONG macro which is defined as long on Windows (LLP64), and int when targeting LP64 systems. Without this behavior there is no intrinsic for 32 bit rotates on these platforms.
1 parent bbc257c commit 55175c1

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

clang/include/clang/Basic/Builtins.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,12 @@ LANGBUILTIN(_ReturnAddress, "v*", "n", ALL_MS_LANGUAGES)
942942
LANGBUILTIN(_rotl8, "UcUcUc", "n", ALL_MS_LANGUAGES)
943943
LANGBUILTIN(_rotl16, "UsUsUc", "n", ALL_MS_LANGUAGES)
944944
LANGBUILTIN(_rotl, "UiUii", "n", ALL_MS_LANGUAGES)
945-
LANGBUILTIN(_lrotl, "ULiULii", "n", ALL_MS_LANGUAGES)
945+
LANGBUILTIN(_lrotl, "UNiUNii", "n", ALL_MS_LANGUAGES)
946946
LANGBUILTIN(_rotl64, "UWiUWii", "n", ALL_MS_LANGUAGES)
947947
LANGBUILTIN(_rotr8, "UcUcUc", "n", ALL_MS_LANGUAGES)
948948
LANGBUILTIN(_rotr16, "UsUsUc", "n", ALL_MS_LANGUAGES)
949949
LANGBUILTIN(_rotr, "UiUii", "n", ALL_MS_LANGUAGES)
950-
LANGBUILTIN(_lrotr, "ULiULii", "n", ALL_MS_LANGUAGES)
950+
LANGBUILTIN(_lrotr, "UNiUNii", "n", ALL_MS_LANGUAGES)
951951
LANGBUILTIN(_rotr64, "UWiUWii", "n", ALL_MS_LANGUAGES)
952952
LANGBUILTIN(__va_start, "vc**.", "nt", ALL_MS_LANGUAGES)
953953
LANGBUILTIN(__fastfail, "vUi", "nr", ALL_MS_LANGUAGES)

clang/test/CodeGen/ms-intrinsics-rotations.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
1313
// RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
1414
// RUN: -triple x86_64--linux -emit-llvm %s -o - \
15-
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
15+
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
1616
// RUN: %clang_cc1 -ffreestanding -fms-extensions \
1717
// RUN: -triple x86_64--darwin -emit-llvm %s -o - \
18-
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
18+
// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
19+
20+
// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions)
21+
#ifdef __LP64__
22+
#define LONG int
23+
#else
24+
#define LONG long
25+
#endif
1926

2027
// rotate left
2128

@@ -40,15 +47,12 @@ unsigned int test_rotl(unsigned int value, int shift) {
4047
// CHECK: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
4148
// CHECK: ret i32 [[R]]
4249

43-
unsigned long test_lrotl(unsigned long value, int shift) {
50+
unsigned LONG test_lrotl(unsigned LONG value, int shift) {
4451
return _lrotl(value, shift);
4552
}
4653
// CHECK-32BIT-LONG: i32 @test_lrotl
4754
// CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
4855
// CHECK-32BIT-LONG: ret i32 [[R]]
49-
// CHECK-64BIT-LONG: i64 @test_lrotl
50-
// CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshl.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
51-
// CHECK-64BIT-LONG: ret i64 [[R]]
5256

5357
unsigned __int64 test_rotl64(unsigned __int64 value, int shift) {
5458
return _rotl64(value, shift);
@@ -80,15 +84,12 @@ unsigned int test_rotr(unsigned int value, int shift) {
8084
// CHECK: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
8185
// CHECK: ret i32 [[R]]
8286

83-
unsigned long test_lrotr(unsigned long value, int shift) {
87+
unsigned LONG test_lrotr(unsigned LONG value, int shift) {
8488
return _lrotr(value, shift);
8589
}
8690
// CHECK-32BIT-LONG: i32 @test_lrotr
8791
// CHECK-32BIT-LONG: [[R:%.*]] = call i32 @llvm.fshr.i32(i32 [[X:%.*]], i32 [[X]], i32 [[Y:%.*]])
8892
// CHECK-32BIT-LONG: ret i32 [[R]]
89-
// CHECK-64BIT-LONG: i64 @test_lrotr
90-
// CHECK-64BIT-LONG: [[R:%.*]] = call i64 @llvm.fshr.i64(i64 [[X:%.*]], i64 [[X]], i64 [[Y:%.*]])
91-
// CHECK-64BIT-LONG: ret i64 [[R]]
9293

9394
unsigned __int64 test_rotr64(unsigned __int64 value, int shift) {
9495
return _rotr64(value, shift);

0 commit comments

Comments
 (0)