1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i64 @test_ptrauth_nop(ptr %p) {
5 ; CHECK-LABEL: @test_ptrauth_nop(
6 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
7 ; CHECK-NEXT: ret i64 [[TMP0]]
9 %tmp0 = ptrtoint ptr %p to i64
10 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234)
11 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234)
18 define i64 @test_ptrauth_nop_constant() {
19 ; CHECK-LABEL: @test_ptrauth_nop_constant(
20 ; CHECK-NEXT: ret i64 ptrtoint (ptr @foo to i64)
22 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234)
26 define i64 @test_ptrauth_nop_constant_addrdisc() {
27 ; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc(
28 ; CHECK-NEXT: ret i64 ptrtoint (ptr @foo to i64)
30 %addr = ptrtoint ptr @foo to i64
31 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234)
32 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
36 define i64 @test_ptrauth_nop_mismatch(ptr %p) {
37 ; CHECK-LABEL: @test_ptrauth_nop_mismatch(
38 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
39 ; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 1, i64 1234)
40 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 10)
41 ; CHECK-NEXT: ret i64 [[AUTHED]]
43 %tmp0 = ptrtoint ptr %p to i64
44 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234)
45 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 10)
49 define i64 @test_ptrauth_nop_mismatch_keys(ptr %p) {
50 ; CHECK-LABEL: @test_ptrauth_nop_mismatch_keys(
51 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
52 ; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 0, i64 1234)
53 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 1, i64 1234)
54 ; CHECK-NEXT: ret i64 [[AUTHED]]
56 %tmp0 = ptrtoint ptr %p to i64
57 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 0, i64 1234)
58 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 1, i64 1234)
62 define i64 @test_ptrauth_sign_resign(ptr %p) {
63 ; CHECK-LABEL: @test_ptrauth_sign_resign(
64 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
65 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.sign(i64 [[TMP0]], i32 0, i64 42)
66 ; CHECK-NEXT: ret i64 [[AUTHED]]
68 %tmp0 = ptrtoint ptr %p to i64
69 %signed = call i64 @llvm.ptrauth.sign(i64 %tmp0, i32 1, i64 1234)
70 %authed = call i64 @llvm.ptrauth.resign(i64 %signed, i32 1, i64 1234, i32 0, i64 42)
74 define i64 @test_ptrauth_resign_resign(ptr %p) {
75 ; CHECK-LABEL: @test_ptrauth_resign_resign(
76 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
77 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.resign(i64 [[TMP0]], i32 1, i64 1234, i32 1, i64 3141)
78 ; CHECK-NEXT: ret i64 [[AUTHED]]
80 %tmp0 = ptrtoint ptr %p to i64
81 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 42)
82 %authed = call i64 @llvm.ptrauth.resign(i64 %signed, i32 0, i64 42, i32 1, i64 3141)
86 define i64 @test_ptrauth_resign_auth(ptr %p) {
87 ; CHECK-LABEL: @test_ptrauth_resign_auth(
88 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
89 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[TMP0]], i32 1, i64 1234)
90 ; CHECK-NEXT: ret i64 [[AUTHED]]
92 %tmp0 = ptrtoint ptr %p to i64
93 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 42)
94 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 0, i64 42)
98 define i64 @test_ptrauth_resign_auth_mismatch(ptr %p) {
99 ; CHECK-LABEL: @test_ptrauth_resign_auth_mismatch(
100 ; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
101 ; CHECK-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.resign(i64 [[TMP0]], i32 1, i64 1234, i32 0, i64 10)
102 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[SIGNED]], i32 0, i64 42)
103 ; CHECK-NEXT: ret i64 [[AUTHED]]
105 %tmp0 = ptrtoint ptr %p to i64
106 %signed = call i64 @llvm.ptrauth.resign(i64 %tmp0, i32 1, i64 1234, i32 0, i64 10)
107 %authed = call i64 @llvm.ptrauth.auth(i64 %signed, i32 0, i64 42)
111 define i64 @test_ptrauth_nop_constant_mismatch() {
112 ; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch(
113 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12)
114 ; CHECK-NEXT: ret i64 [[AUTHED]]
116 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12)
120 define i64 @test_ptrauth_nop_constant_mismatch_key() {
121 ; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch_key(
122 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234)
123 ; CHECK-NEXT: ret i64 [[AUTHED]]
125 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234)
129 define i64 @test_ptrauth_nop_constant_addrdisc_mismatch() {
130 ; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch(
131 ; CHECK-NEXT: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @foo to i64), i64 12)
132 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]])
133 ; CHECK-NEXT: ret i64 [[AUTHED]]
135 %addr = ptrtoint ptr @foo to i64
136 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 12)
137 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
141 define i64 @test_ptrauth_nop_constant_addrdisc_mismatch2() {
142 ; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch2(
143 ; CHECK-NEXT: [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @bar to i64), i64 1234)
144 ; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]])
145 ; CHECK-NEXT: ret i64 [[AUTHED]]
147 %addr = ptrtoint ptr @bar to i64
148 %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234)
149 %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
153 define i64 @test_ptrauth_resign_ptrauth_constant(ptr %p) {
154 ; CHECK-LABEL: @test_ptrauth_resign_ptrauth_constant(
155 ; CHECK-NEXT: ret i64 ptrtoint (ptr ptrauth (ptr @foo, i32 0, i64 42) to i64)
158 %tmp0 = ptrtoint ptr %p to i64
159 %authed = call i64 @llvm.ptrauth.resign(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234, i32 0, i64 42)
163 declare i64 @llvm.ptrauth.auth(i64, i32, i64)
164 declare i64 @llvm.ptrauth.sign(i64, i32, i64)
165 declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64)
166 declare i64 @llvm.ptrauth.blend(i64, i64)