Peter Collingbourne 75bb30ddbf
Move {load,store}(llvm.protected.field.ptr) lowering to InstCombine.
The previous position of llvm.protected.field.ptr lowering for loads
and stores was problematic as it not only inhibited optimizations such
as DSE (as stores to a llvm.protected.field.ptr were not considered to
must-alias stores to the non-protected.field pointer) but also required
changes to other optimization passes to avoid transformations that would
reduce PFP coverage.

Address this by moving the load/store part of the lowering to
InstCombine, where it will run earlier than the PFP-breaking and
AA-relying transformations. The deactivation symbol, null comparison
and EmuPAC parts of the lowering remain in PreISelLowering.

Now that the transformation inhibitions are no longer needed, remove them
(i.e. partially revert #151649, and revert #182976).

This change resulted in a 2.4% reduction in Fleetbench .text size and
the following improvements to PFP performance overhead for BM_PROTO_Arena
on various microarchitectures:

                    before   after
  Apple M2 Ultra     3.5%    3.3%
  Google Axion C4A   3.3%    2.9%
  Google Axion N4A   2.7%    2.2%

Reviewers: fmayer, nikic, vitalybuka

Reviewed By: fmayer

Pull Request: https://github.com/llvm/llvm-project/pull/186548
2026-04-06 17:47:24 -07:00

65 lines
2.8 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -passes=pre-isel-intrinsic-lowering -mtriple aarch64-unknown-linux -S < %s | FileCheck --check-prefix=NOPAUTH %s
; RUN: opt -passes=pre-isel-intrinsic-lowering -mtriple aarch64-unknown-linux -mattr=+pauth -S < %s | FileCheck --check-prefix=PAUTH1 %s
; RUN: opt -passes=pre-isel-intrinsic-lowering -mtriple arm64e-apple-darwin -S < %s | FileCheck --check-prefix=PAUTH2 %s
@ds = external global i8
define i64 @sign1(i64 %p) {
; NOPAUTH-LABEL: define i64 @sign1(
; NOPAUTH-SAME: i64 [[P:%.*]]) {
; NOPAUTH-NEXT: [[TMP1:%.*]] = call i64 @__emupac_autda(i64 [[P]], i64 1)
; NOPAUTH-NEXT: ret i64 [[TMP1]]
;
; PAUTH1-LABEL: define i64 @sign1(
; PAUTH1-SAME: i64 [[P:%.*]]) #[[ATTR0:[0-9]+]] {
; PAUTH1-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 2, i64 1)
; PAUTH1-NEXT: ret i64 [[SIGNED]]
;
; PAUTH2-LABEL: define i64 @sign1(
; PAUTH2-SAME: i64 [[P:%.*]]) {
; PAUTH2-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 2, i64 1)
; PAUTH2-NEXT: ret i64 [[SIGNED]]
;
%signed = call i64 @llvm.ptrauth.auth(i64 %p, i32 2, i64 1)
ret i64 %signed
}
define i64 @sign2(i64 %p) {
; NOPAUTH-LABEL: define i64 @sign2(
; NOPAUTH-SAME: i64 [[P:%.*]]) {
; NOPAUTH-NEXT: [[TMP1:%.*]] = call i64 @__emupac_autda(i64 [[P]], i64 1) [ "deactivation-symbol"(ptr @ds) ]
; NOPAUTH-NEXT: ret i64 [[TMP1]]
;
; PAUTH1-LABEL: define i64 @sign2(
; PAUTH1-SAME: i64 [[P:%.*]]) #[[ATTR0]] {
; PAUTH1-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 2, i64 1) [ "deactivation-symbol"(ptr @ds) ]
; PAUTH1-NEXT: ret i64 [[SIGNED]]
;
; PAUTH2-LABEL: define i64 @sign2(
; PAUTH2-SAME: i64 [[P:%.*]]) {
; PAUTH2-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 2, i64 1) [ "deactivation-symbol"(ptr @ds) ]
; PAUTH2-NEXT: ret i64 [[SIGNED]]
;
%signed = call i64 @llvm.ptrauth.auth(i64 %p, i32 2, i64 1) [ "deactivation-symbol"(ptr @ds) ]
ret i64 %signed
}
define i64 @sign3(i64 %p) {
; NOPAUTH-LABEL: define i64 @sign3(
; NOPAUTH-SAME: i64 [[P:%.*]]) {
; NOPAUTH-NEXT: [[TMP1:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 0, i64 1) [ "deactivation-symbol"(ptr @ds) ]
; NOPAUTH-NEXT: ret i64 [[TMP1]]
;
; PAUTH1-LABEL: define i64 @sign3(
; PAUTH1-SAME: i64 [[P:%.*]]) #[[ATTR0]] {
; PAUTH1-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 0, i64 1) [ "deactivation-symbol"(ptr @ds) ]
; PAUTH1-NEXT: ret i64 [[SIGNED]]
;
; PAUTH2-LABEL: define i64 @sign3(
; PAUTH2-SAME: i64 [[P:%.*]]) {
; PAUTH2-NEXT: [[SIGNED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[P]], i32 0, i64 1) [ "deactivation-symbol"(ptr @ds) ]
; PAUTH2-NEXT: ret i64 [[SIGNED]]
;
%signed = call i64 @llvm.ptrauth.auth(i64 %p, i32 0, i64 1) [ "deactivation-symbol"(ptr @ds) ]
ret i64 %signed
}