Skip to content

Commit cf9b917

Browse files
committed
[AArch64][PAC] Precommit tests on merging MOVaddr/LOADgotAUTH with PAC*
1 parent f7c8856 commit cf9b917

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-constant-in-code.ll

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,82 @@ define ptr @foo() {
7878
ret ptr ptrauth (ptr @g, i32 0)
7979
}
8080

81+
;--- finalize-isel.ll
82+
83+
; RUN: llc < finalize-isel.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=1 \
84+
; RUN: -verify-machineinstrs -global-isel-abort=1 -stop-after=finalize-isel | \
85+
; RUN: FileCheck --check-prefixes=ISEL,ISEL-ELF %s
86+
; RUN: llc < finalize-isel.ll -mtriple arm64-apple-ios -mattr=+pauth -global-isel=1 \
87+
; RUN: -verify-machineinstrs -global-isel-abort=1 -stop-after=finalize-isel | \
88+
; RUN: FileCheck --check-prefixes=ISEL %s
89+
90+
@const_table_local = dso_local constant [3 x ptr] [ptr null, ptr null, ptr null]
91+
@const_table_got = constant [3 x ptr] [ptr null, ptr null, ptr null]
92+
93+
define void @store_signed_const_local(ptr %dest) {
94+
; ISEL-LABEL: name: store_signed_const_local
95+
; ISEL: body:
96+
; ISEL: %0:gpr64common = COPY $x0
97+
; ISEL-NEXT: %10:gpr64common = MOVaddr target-flags(aarch64-page) @const_table_local + 8, target-flags(aarch64-pageoff, aarch64-nc) @const_table_local + 8
98+
; ISEL-NEXT: %2:gpr64noip = MOVKXi %0, 1234
99+
; ISEL-NEXT: %15:gpr64noip = COPY %0
100+
; ISEL-NEXT: %4:gpr64 = PAC %10, 2, 1234, %15, implicit-def dead $x16, implicit-def dead $x17
101+
; ISEL-NEXT: %14:gpr64 = COPY %4
102+
; ISEL-NEXT: STRXui %14, %0, 0 :: (store (p0) into %ir.dest)
103+
; ISEL-NEXT: RET_ReallyLR
104+
%dest.i = ptrtoint ptr %dest to i64
105+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
106+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_local, i32 0, i32 1) to i64), i32 2, i64 %discr)
107+
%signed.ptr = inttoptr i64 %signed.i to ptr
108+
store ptr %signed.ptr, ptr %dest
109+
ret void
110+
}
111+
112+
define void @store_signed_const_got(ptr %dest) {
113+
; ISEL-ELF-LABEL: name: store_signed_const_got
114+
; ISEL-ELF: body:
115+
; ISEL-ELF: %0:gpr64common = COPY $x0
116+
; ISEL-ELF-NEXT: %7:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got
117+
; ISEL-ELF-NEXT: %6:gpr64common = ADDXri %7, 8, 0
118+
; ISEL-ELF-NEXT: %2:gpr64noip = MOVKXi %0, 1234
119+
; ISEL-ELF-NEXT: %12:gpr64noip = COPY %0
120+
; ISEL-ELF-NEXT: %4:gpr64 = PAC %6, 2, 1234, %12, implicit-def dead $x16, implicit-def dead $x17
121+
; ISEL-ELF-NEXT: %10:gpr64 = COPY %4
122+
; ISEL-ELF-NEXT: STRXui %10, %0, 0 :: (store (p0) into %ir.dest)
123+
; ISEL-ELF-NEXT: RET_ReallyLR
124+
%dest.i = ptrtoint ptr %dest to i64
125+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
126+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_got, i32 0, i32 1) to i64), i32 2, i64 %discr)
127+
%signed.ptr = inttoptr i64 %signed.i to ptr
128+
store ptr %signed.ptr, ptr %dest
129+
ret void
130+
}
131+
132+
define void @store_signed_arg(ptr %dest, ptr %p) {
133+
; ISEL-LABEL: name: store_signed_arg
134+
; ISEL: body:
135+
; ISEL: %0:gpr64common = COPY $x0
136+
; ISEL-NEXT: %1:gpr64common = COPY $x1
137+
; ISEL-NEXT: %3:gpr64noip = MOVKXi %0, 1234
138+
; ISEL-NEXT: %6:gpr64common = ADDXri %1, 8, 0
139+
; ISEL-NEXT: %12:gpr64noip = COPY %0
140+
; ISEL-NEXT: %8:gpr64 = PAC %6, 2, 1234, %12, implicit-def dead $x16, implicit-def dead $x17
141+
; ISEL-NEXT: %10:gpr64 = COPY %8
142+
; ISEL-NEXT: STRXui %10, %0, 0 :: (store (p0) into %ir.dest)
143+
; ISEL-NEXT: RET_ReallyLR
144+
%dest.i = ptrtoint ptr %dest to i64
145+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
146+
%p.offset = getelementptr [2 x ptr], ptr %p, i32 0, i32 1
147+
%p.offset.i = ptrtoint ptr %p.offset to i64
148+
%signed.i = call i64 @llvm.ptrauth.sign(i64 %p.offset.i, i32 2, i64 %discr)
149+
%signed.ptr = inttoptr i64 %signed.i to ptr
150+
store ptr %signed.ptr, ptr %dest
151+
ret void
152+
}
153+
154+
!llvm.module.flags = !{!0}
155+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
156+
81157
;--- ok.ll
82158

83159
; RUN: llc < ok.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=1 \

llvm/test/CodeGen/AArch64/ptrauth-constant-in-code.ll

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,77 @@ define ptr @foo() {
6969
ret ptr ptrauth (ptr @g, i32 0)
7070
}
7171

72+
;--- finalize-isel.ll
73+
74+
; RUN: llc < finalize-isel.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=0 \
75+
; RUN: -verify-machineinstrs -stop-after=finalize-isel | FileCheck --check-prefixes=ISEL,ISEL-ELF %s
76+
; RUN: llc < finalize-isel.ll -mtriple arm64-apple-ios -mattr=+pauth -global-isel=0 \
77+
; RUN: -verify-machineinstrs -stop-after=finalize-isel | FileCheck --check-prefixes=ISEL %s
78+
79+
@const_table_local = dso_local constant [3 x ptr] [ptr null, ptr null, ptr null]
80+
@const_table_got = constant [3 x ptr] [ptr null, ptr null, ptr null]
81+
82+
define void @store_signed_const_local(ptr %dest) {
83+
; ISEL-LABEL: name: store_signed_const_local
84+
; ISEL: body:
85+
; ISEL: %0:gpr64common = COPY $x0
86+
; ISEL-NEXT: %1:gpr64noip = MOVKXi %0, 1234
87+
; ISEL-NEXT: %2:gpr64common = MOVaddr target-flags(aarch64-page) @const_table_local + 8, target-flags(aarch64-pageoff, aarch64-nc) @const_table_local + 8
88+
; ISEL-NEXT: %4:gpr64noip = COPY %0
89+
; ISEL-NEXT: %3:gpr64 = PAC %2, 2, 1234, killed %4, implicit-def dead $x16, implicit-def dead $x17
90+
; ISEL-NEXT: STRXui killed %3, %0, 0 :: (store (s64) into %ir.dest)
91+
; ISEL-NEXT: RET_ReallyLR
92+
%dest.i = ptrtoint ptr %dest to i64
93+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
94+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_local, i32 0, i32 1) to i64), i32 2, i64 %discr)
95+
%signed.ptr = inttoptr i64 %signed.i to ptr
96+
store ptr %signed.ptr, ptr %dest
97+
ret void
98+
}
99+
100+
define void @store_signed_const_got(ptr %dest) {
101+
; ISEL-ELF-LABEL: name: store_signed_const_got
102+
; ISEL-ELF: body:
103+
; ISEL-ELF: %0:gpr64common = COPY $x0
104+
; ISEL-ELF-NEXT: %1:gpr64noip = MOVKXi %0, 1234
105+
; ISEL-ELF-NEXT: %2:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got, implicit-def dead $x16, implicit-def dead $x17, implicit-def dead $nzcv
106+
; ISEL-ELF-NEXT: %3:gpr64common = ADDXri killed %2, 8, 0
107+
; ISEL-ELF-NEXT: %5:gpr64noip = COPY %0
108+
; ISEL-ELF-NEXT: %4:gpr64 = PAC %3, 2, 1234, killed %5, implicit-def dead $x16, implicit-def dead $x17
109+
; ISEL-ELF-NEXT: STRXui killed %4, %0, 0 :: (store (s64) into %ir.dest)
110+
; ISEL-ELF-NEXT: RET_ReallyLR
111+
%dest.i = ptrtoint ptr %dest to i64
112+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
113+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_got, i32 0, i32 1) to i64), i32 2, i64 %discr)
114+
%signed.ptr = inttoptr i64 %signed.i to ptr
115+
store ptr %signed.ptr, ptr %dest
116+
ret void
117+
}
118+
119+
define void @store_signed_arg(ptr %dest, ptr %p) {
120+
; ISEL-LABEL: name: store_signed_arg
121+
; ISEL: body:
122+
; ISEL: %1:gpr64common = COPY $x1
123+
; ISEL-NEXT: %0:gpr64common = COPY $x0
124+
; ISEL-NEXT: %2:gpr64noip = MOVKXi %0, 1234
125+
; ISEL-NEXT: %3:gpr64common = ADDXri %1, 8, 0
126+
; ISEL-NEXT: %5:gpr64noip = COPY %0
127+
; ISEL-NEXT: %4:gpr64 = PAC %3, 2, 1234, killed %5, implicit-def dead $x16, implicit-def dead $x17
128+
; ISEL-NEXT: STRXui killed %4, %0, 0 :: (store (s64) into %ir.dest)
129+
; ISEL-NEXT: RET_ReallyLR
130+
%dest.i = ptrtoint ptr %dest to i64
131+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
132+
%p.offset = getelementptr [2 x ptr], ptr %p, i32 0, i32 1
133+
%p.offset.i = ptrtoint ptr %p.offset to i64
134+
%signed.i = call i64 @llvm.ptrauth.sign(i64 %p.offset.i, i32 2, i64 %discr)
135+
%signed.ptr = inttoptr i64 %signed.i to ptr
136+
store ptr %signed.ptr, ptr %dest
137+
ret void
138+
}
139+
140+
!llvm.module.flags = !{!0}
141+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
142+
72143
;--- ok.ll
73144

74145
; RUN: llc < ok.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=0 \

0 commit comments

Comments
 (0)