Skip to content

Commit 4fd1b86

Browse files
Ami-zhangtstellar
authored andcommitted
[Analysis][LoongArch] Add sign extension for i32 parameters and returns
In LoongArch ABI spec, we can see that in the LP64D ABI, unsigned 32-bit types, such as unsigned int, are stored in general-purpose registers as proper sign extensions of their 32-bit values. Reference: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_abi_lp64d Reviewed By: SixWeining, xen0n Differential Revision: https://reviews.llvm.org/D151794 (cherry picked from commit fe6716a)
1 parent 74b5a0a commit 4fd1b86

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,14 @@ class TargetLibraryInfo {
408408
ShouldExtI32Param = true;
409409
ShouldExtI32Return = true;
410410
}
411-
// Mips and riscv64, on the other hand, needs signext on i32 parameters
412-
// corresponding to both signed and unsigned ints.
413-
if (T.isMIPS() || T.isRISCV64()) {
411+
// LoongArch, Mips, and riscv64, on the other hand, need signext on i32
412+
// parameters corresponding to both signed and unsigned ints.
413+
if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
414414
ShouldSignExtI32Param = true;
415415
}
416-
// riscv64 needs signext on i32 returns corresponding to both signed and
417-
// unsigned ints.
418-
if (T.isRISCV64()) {
416+
// LoongArch and riscv64 need signext on i32 returns corresponding to both
417+
// signed and unsigned ints.
418+
if (T.isLoongArch() || T.isRISCV64()) {
419419
ShouldSignExtI32Return = true;
420420
}
421421
}

llvm/test/Instrumentation/AddressSanitizer/experiment.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
; RUN: opt < %s -passes=asan -asan-force-experiment=42 -S | FileCheck %s
44
; RUN: opt < %s -passes=asan -asan-force-experiment=42 -S -mtriple=s390x-unknown-linux | FileCheck %s --check-prefix=EXT
55
; RUN: opt < %s -passes=asan -asan-force-experiment=42 -S -mtriple=mips-linux-gnu | FileCheck %s --check-prefix=MIPS_EXT
6-
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target
6+
; RUN: opt < %s -passes=asan -asan-force-experiment=42 -S -mtriple=loongarch64-unknown-linux-gnu | FileCheck %s --check-prefix=LA_EXT
7+
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target, loongarch-registered-target
78

89
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
910
target triple = "x86_64-unknown-linux-gnu"
@@ -119,15 +120,19 @@ entry:
119120
; CHECK: declare void @__asan_report_exp_load_n(i64, i64, i32)
120121
; EXT: declare void @__asan_report_exp_load_n(i64, i64, i32 zeroext)
121122
; MIPS_EXT: declare void @__asan_report_exp_load_n(i64, i64, i32 signext)
123+
; LA_EXT: declare void @__asan_report_exp_load_n(i64, i64, i32 signext)
122124

123125
; CHECK: declare void @__asan_exp_loadN(i64, i64, i32)
124126
; EXT: declare void @__asan_exp_loadN(i64, i64, i32 zeroext)
125127
; MIPS_EXT: declare void @__asan_exp_loadN(i64, i64, i32 signext)
128+
; LA_EXT: declare void @__asan_exp_loadN(i64, i64, i32 signext)
126129

127130
; CHECK: declare void @__asan_report_exp_load1(i64, i32)
128131
; EXT: declare void @__asan_report_exp_load1(i64, i32 zeroext)
129132
; MIPS_EXT: declare void @__asan_report_exp_load1(i64, i32 signext)
133+
; LA_EXT: declare void @__asan_report_exp_load1(i64, i32 signext)
130134

131135
; CHECK: declare void @__asan_exp_load1(i64, i32)
132136
; EXT: declare void @__asan_exp_load1(i64, i32 zeroext)
133137
; MIPS_EXT: declare void @__asan_exp_load1(i64, i32 signext)
138+
; LA_EXT: declare void @__asan_exp_load1(i64, i32 signext)

llvm/test/Instrumentation/AddressSanitizer/mem-intrinsics.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
; RUN: opt < %s -passes=asan -asan-kernel -asan-kernel-mem-intrinsic-prefix -S | FileCheck --check-prefixes=CHECK,CHECK-PREFIX %s
66
; RUN: opt < %s -passes=asan -S -mtriple=s390x-unknown-linux | FileCheck --check-prefix=EXT %s
77
; RUN: opt < %s -passes=asan -S -mtriple=mips-linux-gnu | FileCheck --check-prefix=MIPS_EXT %s
8-
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target
8+
; RUN: opt < %s -passes=asan -S -mtriple=loongarch64-unknown-linux-gnu | FileCheck --check-prefix=LA_EXT %s
9+
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target, loongarch-registered-target
910

1011
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
1112
target triple = "x86_64-unknown-linux-gnu"
@@ -80,3 +81,4 @@ define void @memintr_element_atomic_test(ptr %a, ptr %b) nounwind uwtable saniti
8081
; CHECK-PREFIX: declare ptr @__asan_memset(ptr, i32, i64)
8182
; EXT: declare ptr @__asan_memset(ptr, i32 zeroext, i64)
8283
; MIPS_EXT: declare ptr @__asan_memset(ptr, i32 signext, i64)
84+
; LA_EXT: declare ptr @__asan_memset(ptr, i32 signext, i64)

llvm/test/Instrumentation/ThreadSanitizer/atomic.ll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
; RUN: opt < %s -passes=tsan -S | FileCheck %s
22
; RUN: opt < %s -passes=tsan -S -mtriple=s390x-unknown-linux | FileCheck --check-prefix=EXT %s
33
; RUN: opt < %s -passes=tsan -S -mtriple=mips-linux-gnu | FileCheck --check-prefix=MIPS_EXT %s
4-
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target
4+
; RUN: opt < %s -passes=tsan -S -mtriple=loongarch64-unknown-linux-gnu | FileCheck --check-prefix=LA_EXT %s
5+
; REQUIRES: x86-registered-target, systemz-registered-target, mips-registered-target, loongarch-registered-target
56
; Check that atomic memory operations are converted to calls into ThreadSanitizer runtime.
67
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
78

@@ -2102,38 +2103,47 @@ entry:
21022103
; CHECK: declare void @__tsan_atomic32_store(ptr, i32, i32)
21032104
; EXT: declare void @__tsan_atomic32_store(ptr, i32 signext, i32 signext)
21042105
; MIPS_EXT: declare void @__tsan_atomic32_store(ptr, i32 signext, i32 signext)
2106+
; LA_EXT: declare void @__tsan_atomic32_store(ptr, i32 signext, i32 signext)
21052107

21062108
; CHECK: declare i32 @__tsan_atomic32_compare_exchange_val(ptr, i32, i32, i32, i32)
21072109
; EXT: declare signext i32 @__tsan_atomic32_compare_exchange_val(ptr, i32 signext, i32 signext, i32 signext, i32 signext)
21082110
; MIPS_EXT: declare i32 @__tsan_atomic32_compare_exchange_val(ptr, i32 signext, i32 signext, i32 signext, i32 signext)
2111+
; LA_EXT: declare signext i32 @__tsan_atomic32_compare_exchange_val(ptr, i32 signext, i32 signext, i32 signext, i32 signext)
21092112

21102113
; CHECK: declare i64 @__tsan_atomic64_load(ptr, i32)
21112114
; EXT: declare i64 @__tsan_atomic64_load(ptr, i32 signext)
21122115
; MIPS_EXT: declare i64 @__tsan_atomic64_load(ptr, i32 signext)
2116+
; LA_EXT: declare i64 @__tsan_atomic64_load(ptr, i32 signext)
21132117

21142118
; CHECK: declare void @__tsan_atomic64_store(ptr, i64, i32)
21152119
; EXT: declare void @__tsan_atomic64_store(ptr, i64, i32 signext)
21162120
; MIPS_EXT: declare void @__tsan_atomic64_store(ptr, i64, i32 signext)
2121+
; LA_EXT: declare void @__tsan_atomic64_store(ptr, i64, i32 signext)
21172122

21182123
; CHECK: declare i64 @__tsan_atomic64_fetch_add(ptr, i64, i32)
21192124
; EXT: declare i64 @__tsan_atomic64_fetch_add(ptr, i64, i32 signext)
21202125
; MIPS_EXT: declare i64 @__tsan_atomic64_fetch_add(ptr, i64, i32 signext)
2126+
; LA_EXT: declare i64 @__tsan_atomic64_fetch_add(ptr, i64, i32 signext)
21212127

21222128
; CHECK: declare i64 @__tsan_atomic64_compare_exchange_val(ptr, i64, i64, i32, i32)
21232129
; EXT: declare i64 @__tsan_atomic64_compare_exchange_val(ptr, i64, i64, i32 signext, i32 signext)
21242130
; MIPS_EXT: declare i64 @__tsan_atomic64_compare_exchange_val(ptr, i64, i64, i32 signext, i32 signext)
2131+
; LA_EXT: declare i64 @__tsan_atomic64_compare_exchange_val(ptr, i64, i64, i32 signext, i32 signext)
21252132

21262133
; CHECK: declare void @__tsan_atomic_thread_fence(i32)
21272134
; EXT: declare void @__tsan_atomic_thread_fence(i32 signext)
21282135
; MIPS_EXT: declare void @__tsan_atomic_thread_fence(i32 signext)
2136+
; LA_EXT: declare void @__tsan_atomic_thread_fence(i32 signext)
21292137

21302138
; CHECK: declare void @__tsan_atomic_signal_fence(i32)
21312139
; EXT: declare void @__tsan_atomic_signal_fence(i32 signext)
21322140
; MIPS_EXT: declare void @__tsan_atomic_signal_fence(i32 signext)
2141+
; LA_EXT: declare void @__tsan_atomic_signal_fence(i32 signext)
21332142

21342143
; CHECK: declare ptr @__tsan_memset(ptr, i32, i64)
21352144
; EXT: declare ptr @__tsan_memset(ptr, i32 signext, i64)
21362145
; MIPS_EXT: declare ptr @__tsan_memset(ptr, i32 signext, i64)
2146+
; LA_EXT: declare ptr @__tsan_memset(ptr, i32 signext, i64)
21372147

21382148
!llvm.module.flags = !{!0, !1, !2}
21392149
!llvm.dbg.cu = !{!8}

0 commit comments

Comments
 (0)