Skip to content

Commit 39067fe

Browse files
committed
[Clang][LoongArch] Fixed incorrect _BitInt(N>64) alignment
This patch makes determining alignment and width of BitInt to be target ABI specific and makes it consistent with [Procedure Call Standard for the LoongArch™ Architecture] for LoongArch target (https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc).
1 parent 5b8664f commit 39067fe

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
5656
SuitableAlign = 128;
5757
WCharType = SignedInt;
5858
WIntType = UnsignedInt;
59+
BitIntMaxAlign = 128;
5960
}
6061

6162
bool setCPU(const std::string &Name) override {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
// RUN: %clang_cc1 -triple loongarch64 -fexperimental-max-bitint-width=1024 -emit-llvm %s -o - | FileCheck %s
3+
4+
void pass_large_BitInt(_BitInt(129));
5+
6+
// CHECK-LABEL: define dso_local void @example_BitInt(
7+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
8+
// CHECK-NEXT: [[ENTRY:.*:]]
9+
// CHECK-NEXT: [[L:%.*]] = alloca i256, align 16
10+
// CHECK-NEXT: [[BYVAL_TEMP:%.*]] = alloca i256, align 16
11+
// CHECK-NEXT: store i256 0, ptr [[L]], align 16
12+
// CHECK-NEXT: [[TMP0:%.*]] = load i256, ptr [[L]], align 16
13+
// CHECK-NEXT: [[LOADEDV:%.*]] = trunc i256 [[TMP0]] to i129
14+
// CHECK-NEXT: [[STOREDV:%.*]] = sext i129 [[LOADEDV]] to i256
15+
// CHECK-NEXT: store i256 [[STOREDV]], ptr [[BYVAL_TEMP]], align 16
16+
// CHECK-NEXT: call void @pass_large_BitInt(ptr noundef [[BYVAL_TEMP]])
17+
// CHECK-NEXT: ret void
18+
//
19+
void example_BitInt(void) {
20+
_BitInt(129) l = {0};
21+
pass_large_BitInt(l);
22+
}
23+
24+
// CHECK-LABEL: define dso_local void @return_large_BitInt(
25+
// CHECK-SAME: ptr dead_on_unwind noalias writable sret(i256) align 16 [[AGG_RESULT:%.*]]) #[[ATTR0]] {
26+
// CHECK-NEXT: [[ENTRY:.*:]]
27+
// CHECK-NEXT: [[RESULT_PTR:%.*]] = alloca ptr, align 8
28+
// CHECK-NEXT: store ptr [[AGG_RESULT]], ptr [[RESULT_PTR]], align 8
29+
// CHECK-NEXT: store i256 0, ptr [[AGG_RESULT]], align 16
30+
// CHECK-NEXT: [[TMP0:%.*]] = load i256, ptr [[AGG_RESULT]], align 16
31+
// CHECK-NEXT: [[LOADEDV:%.*]] = trunc i256 [[TMP0]] to i129
32+
// CHECK-NEXT: [[STOREDV:%.*]] = sext i129 [[LOADEDV]] to i256
33+
// CHECK-NEXT: store i256 [[STOREDV]], ptr [[AGG_RESULT]], align 16
34+
// CHECK-NEXT: ret void
35+
//
36+
_BitInt(129) return_large_BitInt(void) { return 0; }

clang/test/CodeGen/ext-int-cc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -O3 -disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64
2828
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm64_32-apple-ios -target-abi darwinpcs -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=AARCH64DARWIN
2929
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple arm -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=ARM
30-
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
31-
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch32 -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA32
30+
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch64 -O3 -disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA64
31+
// RUN: %clang_cc1 -no-enable-noundef-analysis -triple loongarch32 -O3 -disable-llvm-passes -fexperimental-max-bitint-width=1024 -emit-llvm -o - %s | FileCheck %s --check-prefixes=LA32
3232

3333
// Make sure 128 and 64 bit versions are passed like integers.
3434
void ParamPassing(_BitInt(128) b, _BitInt(64) c) {}
@@ -158,8 +158,8 @@ void ParamPassing4(_BitInt(129) a) {}
158158
// PPC32-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
159159
// AARCH64DARWIN-NOT: define{{.*}} void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
160160
// ARM-NOT: define{{.*}} arm_aapcscc void @ParamPassing4(ptr byval(i129) align 8 %{{.+}})
161-
// LA64-NOT: define{{.*}} void @ParamPassing4(ptr %{{.+}})
162-
// LA32-NOT: define{{.*}} void @ParamPassing4(ptr %{{.+}})
161+
// LA64: define{{.*}} void @ParamPassing4(ptr %{{.+}})
162+
// LA32: define{{.*}} void @ParamPassing4(ptr %{{.+}})
163163
#endif
164164

165165
_BitInt(63) ReturnPassing(void) { return 0; }
@@ -317,8 +317,8 @@ _BitInt(129) ReturnPassing5(void) { return 0; }
317317
// PPC32-NOT: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
318318
// AARCH64DARWIN-NOT: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
319319
// ARM-NOT: define{{.*}} arm_aapcscc void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
320-
// LA64-NOT: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
321-
// LA32-NOT: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
320+
// LA64: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
321+
// LA32: define{{.*}} void @ReturnPassing5(ptr dead_on_unwind noalias writable sret
322322

323323
// SparcV9 is odd in that it has a return-size limit of 256, not 128 or 64
324324
// like other platforms, so test to make sure this behavior will still work.

0 commit comments

Comments
 (0)