Skip to content

Commit 31141b6

Browse files
committed
Unsupport SW encoding
Created using spr 1.3.6-beta.1
1 parent 6178706 commit 31141b6

File tree

4 files changed

+13
-147
lines changed

4 files changed

+13
-147
lines changed

llvm/docs/LangRef.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31762,10 +31762,8 @@ third argument is 1, the pointer is signed (using pointer authentication
3176231762
instructions or emulated PAC if not supported by the hardware) using
3176331763
the discriminator before being stored, and authenticated after being
3176431764
loaded. Note that it is currently unsupported to have the third argument
31765-
be 1 on targets other than AArch64. When the third argument is 0, it is
31766-
rotated left by 16 bits and the discriminator is subtracted before being
31767-
stored, and the discriminator is added and the pointer is rotated right
31768-
by 16 bits after being loaded.
31765+
be 1 on targets other than AArch64, and it is also currently unsupported
31766+
to have the third argument be 0 at all.
3176931767

3177031768
If the pointer is used other than for loading or storing (e.g. its
3177131769
address escapes), that will disable all blending operations using

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static bool expandProtectedFieldPtr(Function &Intr) {
513513
auto *Disc = Call->getArgOperand(1);
514514
bool UseHWEncoding =
515515
cast<ConstantInt>(Call->getArgOperand(2))->getZExtValue();
516+
assert(UseHWEncoding && "software encoding currently unsupported");
516517

517518
auto *DS = GetDeactivationSymbol(Call);
518519
OperandBundleDef DSBundle("deactivation-symbol", DS);
@@ -526,18 +527,7 @@ static bool expandProtectedFieldPtr(Function &Intr) {
526527
IRBuilder<> B(SI);
527528
auto *SIValInt =
528529
B.CreatePtrToInt(SI->getValueOperand(), B.getInt64Ty());
529-
Value *Sign;
530-
if (UseHWEncoding) {
531-
Sign = CreateSign(B, SIValInt, Disc, DSBundle);
532-
} else {
533-
// FIXME: These don't have deactivation symbol attachments, we'll
534-
// need to figure out how to add them.
535-
Sign =
536-
B.CreateIntrinsic(SIValInt->getType(), Intrinsic::fshl,
537-
{SIValInt, SIValInt,
538-
ConstantInt::get(SIValInt->getType(), 16)});
539-
Sign = B.CreateSub(Sign, Disc);
540-
}
530+
Value *Sign = CreateSign(B, SIValInt, Disc, DSBundle);
541531
SI->setOperand(0, B.CreateIntToPtr(Sign, B.getPtrTy()));
542532
SI->setOperand(1, Pointer);
543533
continue;
@@ -554,17 +544,7 @@ static bool expandProtectedFieldPtr(Function &Intr) {
554544
NewLI->setOperand(0, Pointer);
555545
B.Insert(NewLI);
556546
auto *LIInt = B.CreatePtrToInt(NewLI, B.getInt64Ty());
557-
Value *Auth;
558-
if (UseHWEncoding) {
559-
Auth = CreateAuth(B, LIInt, Disc, DSBundle);
560-
} else {
561-
// FIXME: These don't have deactivation symbol attachments, we'll
562-
// need to figure out how to add them.
563-
Auth = B.CreateAdd(LIInt, Disc);
564-
Auth = B.CreateIntrinsic(
565-
Auth->getType(), Intrinsic::fshr,
566-
{Auth, Auth, ConstantInt::get(Auth->getType(), 16)});
567-
}
547+
Value *Auth = CreateAuth(B, LIInt, Disc, DSBundle);
568548
LI->replaceAllUsesWith(B.CreateIntToPtr(Auth, B.getPtrTy()));
569549
LI->eraseFromParent();
570550
continue;

llvm/test/Transforms/PreISelIntrinsicLowering/protected-field-pointer-addrspace1.ll

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,17 @@ target triple = "aarch64-unknown-linux-gnu"
88
@ds2 = external global i8
99
@ds3 = external global i8
1010
@ds4 = external global i8
11-
@ds5 = external global i8
12-
@ds6 = external global i8
1311

1412
;.
1513
; NOPAUTH: @ds1 = external global i8
1614
; NOPAUTH: @ds2 = external global i8
1715
; NOPAUTH: @ds3 = external global i8
18-
; NOPAUTH: @ds4 = external global i8
19-
; NOPAUTH: @ds5 = external global i8
20-
; NOPAUTH: @ds6 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
16+
; NOPAUTH: @ds4 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
2117
;.
2218
; PAUTH: @ds1 = external global i8
2319
; PAUTH: @ds2 = external global i8
2420
; PAUTH: @ds3 = external global i8
25-
; PAUTH: @ds4 = external global i8
26-
; PAUTH: @ds5 = external global i8
27-
; PAUTH: @ds6 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
21+
; PAUTH: @ds4 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
2822
;.
2923
define ptr @load_hw(ptr addrspace(1) %ptrptr) {
3024
; NOPAUTH-LABEL: define ptr @load_hw(
@@ -70,54 +64,6 @@ define void @store_hw(ptr addrspace(1) %ptrptr, ptr %ptr) {
7064
ret void
7165
}
7266

73-
define ptr @load_sw(ptr addrspace(1) %ptrptr) {
74-
; NOPAUTH-LABEL: define ptr @load_sw(
75-
; NOPAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]]) {
76-
; NOPAUTH-NEXT: [[PTR:%.*]] = load ptr, ptr addrspace(1) [[PTRPTR]], align 8
77-
; NOPAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
78-
; NOPAUTH-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 1
79-
; NOPAUTH-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 16)
80-
; NOPAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
81-
; NOPAUTH-NEXT: ret ptr [[TMP4]]
82-
;
83-
; PAUTH-LABEL: define ptr @load_sw(
84-
; PAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]]) #[[ATTR0]] {
85-
; PAUTH-NEXT: [[PTR:%.*]] = load ptr, ptr addrspace(1) [[PTRPTR]], align 8
86-
; PAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
87-
; PAUTH-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 1
88-
; PAUTH-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 16)
89-
; PAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
90-
; PAUTH-NEXT: ret ptr [[TMP4]]
91-
;
92-
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 1, i1 false) [ "deactivation-symbol"(ptr @ds3) ]
93-
%ptr = load ptr, ptr addrspace(1) %protptrptr
94-
ret ptr %ptr
95-
}
96-
97-
define void @store_sw(ptr addrspace(1) %ptrptr, ptr %ptr) {
98-
; NOPAUTH-LABEL: define void @store_sw(
99-
; NOPAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]], ptr [[PTR:%.*]]) {
100-
; NOPAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
101-
; NOPAUTH-NEXT: [[TMP2:%.*]] = call i64 @llvm.fshl.i64(i64 [[TMP1]], i64 [[TMP1]], i64 16)
102-
; NOPAUTH-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 2
103-
; NOPAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
104-
; NOPAUTH-NEXT: store ptr [[TMP4]], ptr addrspace(1) [[PTRPTR]], align 8
105-
; NOPAUTH-NEXT: ret void
106-
;
107-
; PAUTH-LABEL: define void @store_sw(
108-
; PAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]], ptr [[PTR:%.*]]) #[[ATTR0]] {
109-
; PAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
110-
; PAUTH-NEXT: [[TMP2:%.*]] = call i64 @llvm.fshl.i64(i64 [[TMP1]], i64 [[TMP1]], i64 16)
111-
; PAUTH-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 2
112-
; PAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
113-
; PAUTH-NEXT: store ptr [[TMP4]], ptr addrspace(1) [[PTRPTR]], align 8
114-
; PAUTH-NEXT: ret void
115-
;
116-
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 2, i1 false) [ "deactivation-symbol"(ptr @ds4) ]
117-
store ptr %ptr, ptr addrspace(1) %protptrptr
118-
ret void
119-
}
120-
12167
define i1 @compare(ptr addrspace(1) %ptrptr) {
12268
; NOPAUTH-LABEL: define i1 @compare(
12369
; NOPAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]]) {
@@ -133,7 +79,7 @@ define i1 @compare(ptr addrspace(1) %ptrptr) {
13379
; PAUTH-NEXT: [[CMP:%.*]] = or i1 [[CMP1]], [[CMP2]]
13480
; PAUTH-NEXT: ret i1 [[CMP]]
13581
;
136-
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds5) ]
82+
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds3) ]
13783
%cmp1 = icmp eq ptr addrspace(1) %protptrptr, null
13884
%cmp2 = icmp eq ptr addrspace(1) null, %protptrptr
13985
%cmp = or i1 %cmp1, %cmp2
@@ -149,19 +95,17 @@ define ptr addrspace(1) @escape(ptr addrspace(1) %ptrptr) {
14995
; PAUTH-SAME: ptr addrspace(1) [[PTRPTR:%.*]]) #[[ATTR0]] {
15096
; PAUTH-NEXT: ret ptr addrspace(1) [[PTRPTR]]
15197
;
152-
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds6) ]
98+
%protptrptr = call ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1) %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds4) ]
15399
ret ptr addrspace(1) %protptrptr
154100
}
155101

156102
declare ptr addrspace(1) @llvm.protected.field.ptr.p1(ptr addrspace(1), i64, i1 immarg)
157103
;.
158104
; NOPAUTH: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
159105
; NOPAUTH: attributes #[[ATTR1:[0-9]+]] = { nounwind memory(none) }
160-
; NOPAUTH: attributes #[[ATTR2:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
161106
;.
162107
; PAUTH: attributes #[[ATTR0]] = { "target-features"="+pauth" }
163108
; PAUTH: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) "target-features"="+pauth" }
164109
; PAUTH: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
165110
; PAUTH: attributes #[[ATTR3:[0-9]+]] = { nounwind memory(none) }
166-
; PAUTH: attributes #[[ATTR4:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
167111
;.

llvm/test/Transforms/PreISelIntrinsicLowering/protected-field-pointer.ll

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,17 @@ target triple = "aarch64-unknown-linux-gnu"
88
@ds2 = external global i8
99
@ds3 = external global i8
1010
@ds4 = external global i8
11-
@ds5 = external global i8
12-
@ds6 = external global i8
1311

1412
;.
1513
; NOPAUTH: @ds1 = external global i8
1614
; NOPAUTH: @ds2 = external global i8
1715
; NOPAUTH: @ds3 = external global i8
18-
; NOPAUTH: @ds4 = external global i8
19-
; NOPAUTH: @ds5 = external global i8
20-
; NOPAUTH: @ds6 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
16+
; NOPAUTH: @ds4 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
2117
;.
2218
; PAUTH: @ds1 = external global i8
2319
; PAUTH: @ds2 = external global i8
2420
; PAUTH: @ds3 = external global i8
25-
; PAUTH: @ds4 = external global i8
26-
; PAUTH: @ds5 = external global i8
27-
; PAUTH: @ds6 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
21+
; PAUTH: @ds4 = hidden alias i8, inttoptr (i64 3573751839 to ptr)
2822
;.
2923
define ptr @load_hw(ptr %ptrptr) {
3024
; NOPAUTH-LABEL: define ptr @load_hw(
@@ -70,54 +64,6 @@ define void @store_hw(ptr %ptrptr, ptr %ptr) {
7064
ret void
7165
}
7266

73-
define ptr @load_sw(ptr %ptrptr) {
74-
; NOPAUTH-LABEL: define ptr @load_sw(
75-
; NOPAUTH-SAME: ptr [[PTRPTR:%.*]]) {
76-
; NOPAUTH-NEXT: [[PTR:%.*]] = load ptr, ptr [[PTRPTR]], align 8
77-
; NOPAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
78-
; NOPAUTH-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 1
79-
; NOPAUTH-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 16)
80-
; NOPAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
81-
; NOPAUTH-NEXT: ret ptr [[TMP4]]
82-
;
83-
; PAUTH-LABEL: define ptr @load_sw(
84-
; PAUTH-SAME: ptr [[PTRPTR:%.*]]) #[[ATTR0]] {
85-
; PAUTH-NEXT: [[PTR:%.*]] = load ptr, ptr [[PTRPTR]], align 8
86-
; PAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
87-
; PAUTH-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 1
88-
; PAUTH-NEXT: [[TMP3:%.*]] = call i64 @llvm.fshr.i64(i64 [[TMP2]], i64 [[TMP2]], i64 16)
89-
; PAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
90-
; PAUTH-NEXT: ret ptr [[TMP4]]
91-
;
92-
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 1, i1 false) [ "deactivation-symbol"(ptr @ds3) ]
93-
%ptr = load ptr, ptr %protptrptr
94-
ret ptr %ptr
95-
}
96-
97-
define void @store_sw(ptr %ptrptr, ptr %ptr) {
98-
; NOPAUTH-LABEL: define void @store_sw(
99-
; NOPAUTH-SAME: ptr [[PTRPTR:%.*]], ptr [[PTR:%.*]]) {
100-
; NOPAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
101-
; NOPAUTH-NEXT: [[TMP2:%.*]] = call i64 @llvm.fshl.i64(i64 [[TMP1]], i64 [[TMP1]], i64 16)
102-
; NOPAUTH-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 2
103-
; NOPAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
104-
; NOPAUTH-NEXT: store ptr [[TMP4]], ptr [[PTRPTR]], align 8
105-
; NOPAUTH-NEXT: ret void
106-
;
107-
; PAUTH-LABEL: define void @store_sw(
108-
; PAUTH-SAME: ptr [[PTRPTR:%.*]], ptr [[PTR:%.*]]) #[[ATTR0]] {
109-
; PAUTH-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[PTR]] to i64
110-
; PAUTH-NEXT: [[TMP2:%.*]] = call i64 @llvm.fshl.i64(i64 [[TMP1]], i64 [[TMP1]], i64 16)
111-
; PAUTH-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 2
112-
; PAUTH-NEXT: [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
113-
; PAUTH-NEXT: store ptr [[TMP4]], ptr [[PTRPTR]], align 8
114-
; PAUTH-NEXT: ret void
115-
;
116-
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 2, i1 false) [ "deactivation-symbol"(ptr @ds4) ]
117-
store ptr %ptr, ptr %protptrptr
118-
ret void
119-
}
120-
12167
define i1 @compare(ptr %ptrptr) {
12268
; NOPAUTH-LABEL: define i1 @compare(
12369
; NOPAUTH-SAME: ptr [[PTRPTR:%.*]]) {
@@ -133,7 +79,7 @@ define i1 @compare(ptr %ptrptr) {
13379
; PAUTH-NEXT: [[CMP:%.*]] = or i1 [[CMP1]], [[CMP2]]
13480
; PAUTH-NEXT: ret i1 [[CMP]]
13581
;
136-
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds5) ]
82+
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds3) ]
13783
%cmp1 = icmp eq ptr %protptrptr, null
13884
%cmp2 = icmp eq ptr null, %protptrptr
13985
%cmp = or i1 %cmp1, %cmp2
@@ -149,19 +95,17 @@ define ptr @escape(ptr %ptrptr) {
14995
; PAUTH-SAME: ptr [[PTRPTR:%.*]]) #[[ATTR0]] {
15096
; PAUTH-NEXT: ret ptr [[PTRPTR]]
15197
;
152-
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds6) ]
98+
%protptrptr = call ptr @llvm.protected.field.ptr.p0(ptr %ptrptr, i64 3, i1 true) [ "deactivation-symbol"(ptr @ds4) ]
15399
ret ptr %protptrptr
154100
}
155101

156102
declare ptr @llvm.protected.field.ptr.p0(ptr, i64, i1 immarg)
157103
;.
158104
; NOPAUTH: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
159105
; NOPAUTH: attributes #[[ATTR1:[0-9]+]] = { nounwind memory(none) }
160-
; NOPAUTH: attributes #[[ATTR2:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
161106
;.
162107
; PAUTH: attributes #[[ATTR0]] = { "target-features"="+pauth" }
163108
; PAUTH: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) "target-features"="+pauth" }
164109
; PAUTH: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
165110
; PAUTH: attributes #[[ATTR3:[0-9]+]] = { nounwind memory(none) }
166-
; PAUTH: attributes #[[ATTR4:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
167111
;.

0 commit comments

Comments
 (0)