[AMDGPU] Do not internalize ASan device library functions.

ASan device library functions (those starts with the prefix __asan_)
are at the moment undergoing through undesired optimizations due to
internalization. Hence, in order to avoid such undesired optimizations
on ASan device library functions, do not internalize them in the first
place.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D110468
This commit is contained in:
hsmahesha 2021-09-29 07:18:36 +05:30
parent fd9a5b911d
commit c0735cb9f1
2 changed files with 35 additions and 1 deletions

View File

@ -517,7 +517,9 @@ StringRef AMDGPUTargetMachine::getFeatureString(const Function &F) const {
/// Predicate for Internalize pass.
static bool mustPreserveGV(const GlobalValue &GV) {
if (const Function *F = dyn_cast<Function>(&GV))
return F->isDeclaration() || AMDGPU::isEntryFunctionCC(F->getCallingConv());
return F->isDeclaration() || F->getName().startswith("__asan_") ||
F->getName().startswith("__sanitizer_") ||
AMDGPU::isEntryFunctionCC(F->getCallingConv());
GV.removeDeadConstantUsers();
return !GV.use_empty();

View File

@ -0,0 +1,32 @@
; RUN: opt -O0 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=OPTNONE %s
; RUN: opt -passes='default<O0>' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=OPTNONE %s
; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ASAN_NO_INTERNALIZE %s
; RUN: opt -passes='default<O1>' -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ASAN_NO_INTERNALIZE %s
; OPTNONE: define void @__asan_no_explicit_linkage(
; ASAN_NO_INTERNALIZE: define void @__asan_no_explicit_linkage(
define void @__asan_no_explicit_linkage() {
entry:
ret void
}
; OPTNONE: define weak void @__asan_weak_linkage(
; ASAN_NO_INTERNALIZE: define weak void @__asan_weak_linkage(
define weak void @__asan_weak_linkage() {
entry:
ret void
}
; OPTNONE: define void @__sanitizer_no_explicit_linkage(
; ASAN_NO_INTERNALIZE: define void @__sanitizer_no_explicit_linkage(
define void @__sanitizer_no_explicit_linkage() {
entry:
ret void
}
; OPTNONE: define weak void @__sanitizer_weak_linkage(
; ASAN_NO_INTERNALIZE: define weak void @__sanitizer_weak_linkage(
define weak void @__sanitizer_weak_linkage() {
entry:
ret void
}