Skip to content

Commit 1e1844a

Browse files
committed
[AArch64][PAC] Precommit tests on merging MOVaddr/LOADgotAUTH with PAC*
1 parent 52225d2 commit 1e1844a

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,80 @@ 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:gpr64common = PAUTH_BLEND %0, 1234
99+
; ISEL-NEXT: %4:gpr64 = PACDA %10, %2
100+
; ISEL-NEXT: %14:gpr64 = COPY %4
101+
; ISEL-NEXT: STRXui %14, %0, 0 :: (store (p0) into %ir.dest)
102+
; ISEL-NEXT: RET_ReallyLR
103+
%dest.i = ptrtoint ptr %dest to i64
104+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
105+
%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)
106+
%signed.ptr = inttoptr i64 %signed.i to ptr
107+
store ptr %signed.ptr, ptr %dest
108+
ret void
109+
}
110+
111+
define void @store_signed_const_got(ptr %dest) {
112+
; ISEL-ELF-LABEL: name: store_signed_const_got
113+
; ISEL-ELF: body:
114+
; ISEL-ELF: %0:gpr64common = COPY $x0
115+
; ISEL-ELF-NEXT: %7:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got
116+
; ISEL-ELF-NEXT: %6:gpr64common = ADDXri %7, 8, 0
117+
; ISEL-ELF-NEXT: %2:gpr64common = PAUTH_BLEND %0, 1234
118+
; ISEL-ELF-NEXT: %4:gpr64 = PACDA %6, %2
119+
; ISEL-ELF-NEXT: %10:gpr64 = COPY %4
120+
; ISEL-ELF-NEXT: STRXui %10, %0, 0 :: (store (p0) into %ir.dest)
121+
; ISEL-ELF-NEXT: RET_ReallyLR
122+
%dest.i = ptrtoint ptr %dest to i64
123+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
124+
%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)
125+
%signed.ptr = inttoptr i64 %signed.i to ptr
126+
store ptr %signed.ptr, ptr %dest
127+
ret void
128+
}
129+
130+
define void @store_signed_arg(ptr %dest, ptr %p) {
131+
; ISEL-LABEL: name: store_signed_arg
132+
; ISEL: body:
133+
; ISEL: %0:gpr64common = COPY $x0
134+
; ISEL-NEXT: %1:gpr64common = COPY $x1
135+
; ISEL-NEXT: %3:gpr64common = PAUTH_BLEND %0, 1234
136+
; ISEL-NEXT: %6:gpr64common = ADDXri %1, 8, 0
137+
; Check that no implicit defs are added to PACDA instruction.
138+
; ISEL-NEXT: %8:gpr64 = PACDA %6, %3{{$}}
139+
; ISEL-NEXT: %10:gpr64 = COPY %8
140+
; ISEL-NEXT: STRXui %10, %0, 0 :: (store (p0) into %ir.dest)
141+
; ISEL-NEXT: RET_ReallyLR
142+
%dest.i = ptrtoint ptr %dest to i64
143+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
144+
%p.offset = getelementptr [2 x ptr], ptr %p, i32 0, i32 1
145+
%p.offset.i = ptrtoint ptr %p.offset to i64
146+
%signed.i = call i64 @llvm.ptrauth.sign(i64 %p.offset.i, i32 2, i64 %discr)
147+
%signed.ptr = inttoptr i64 %signed.i to ptr
148+
store ptr %signed.ptr, ptr %dest
149+
ret void
150+
}
151+
152+
!llvm.module.flags = !{!0}
153+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
154+
81155
;--- ok.ll
82156

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

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,75 @@ 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:gpr64common = PAUTH_BLEND %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: %3:gpr64 = PACDA %2, killed %1
89+
; ISEL-NEXT: STRXui killed %3, %0, 0 :: (store (s64) into %ir.dest)
90+
; ISEL-NEXT: RET_ReallyLR
91+
%dest.i = ptrtoint ptr %dest to i64
92+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
93+
%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)
94+
%signed.ptr = inttoptr i64 %signed.i to ptr
95+
store ptr %signed.ptr, ptr %dest
96+
ret void
97+
}
98+
99+
define void @store_signed_const_got(ptr %dest) {
100+
; ISEL-ELF-LABEL: name: store_signed_const_got
101+
; ISEL-ELF: body:
102+
; ISEL-ELF: %0:gpr64common = COPY $x0
103+
; ISEL-ELF-NEXT: %1:gpr64common = PAUTH_BLEND %0, 1234
104+
; 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
105+
; ISEL-ELF-NEXT: %3:gpr64common = ADDXri killed %2, 8, 0
106+
; ISEL-ELF-NEXT: %4:gpr64 = PACDA %3, killed %1
107+
; ISEL-ELF-NEXT: STRXui killed %4, %0, 0 :: (store (s64) into %ir.dest)
108+
; ISEL-ELF-NEXT: RET_ReallyLR
109+
%dest.i = ptrtoint ptr %dest to i64
110+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
111+
%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)
112+
%signed.ptr = inttoptr i64 %signed.i to ptr
113+
store ptr %signed.ptr, ptr %dest
114+
ret void
115+
}
116+
117+
define void @store_signed_arg(ptr %dest, ptr %p) {
118+
; ISEL-LABEL: name: store_signed_arg
119+
; ISEL: body:
120+
; ISEL: %1:gpr64common = COPY $x1
121+
; ISEL-NEXT: %0:gpr64common = COPY $x0
122+
; ISEL-NEXT: %2:gpr64common = PAUTH_BLEND %0, 1234
123+
; ISEL-NEXT: %3:gpr64common = ADDXri %1, 8, 0
124+
; Check that no implicit defs are added to PACDA instruction.
125+
; ISEL-NEXT: %4:gpr64 = PACDA %3, killed %2{{$}}
126+
; ISEL-NEXT: STRXui killed %4, %0, 0 :: (store (s64) into %ir.dest)
127+
; ISEL-NEXT: RET_ReallyLR
128+
%dest.i = ptrtoint ptr %dest to i64
129+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
130+
%p.offset = getelementptr [2 x ptr], ptr %p, i32 0, i32 1
131+
%p.offset.i = ptrtoint ptr %p.offset to i64
132+
%signed.i = call i64 @llvm.ptrauth.sign(i64 %p.offset.i, i32 2, i64 %discr)
133+
%signed.ptr = inttoptr i64 %signed.i to ptr
134+
store ptr %signed.ptr, ptr %dest
135+
ret void
136+
}
137+
138+
!llvm.module.flags = !{!0}
139+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
140+
72141
;--- ok.ll
73142

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

0 commit comments

Comments
 (0)