Skip to content

Commit 58fd1de

Browse files
committed
AMDGPU: Consider nobuiltin when querying defined libfuncs
https://reviews.llvm.org/D156708
1 parent d7fcb5b commit 58fd1de

File tree

2 files changed

+80
-9
lines changed

2 files changed

+80
-9
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,16 @@ Function *AMDGPULibFunc::getFunction(Module *M, const AMDGPULibFunc &fInfo) {
954954
std::string FuncName = fInfo.mangle();
955955
Function *F = dyn_cast_or_null<Function>(
956956
M->getValueSymbolTable().lookup(FuncName));
957+
if (!F || F->isDeclaration())
958+
return nullptr;
957959

958-
// check formal with actual types conformance
959-
if (F && !F->isDeclaration() &&
960-
fInfo.isCompatibleSignature(F->getFunctionType()))
961-
return F;
960+
if (F->hasFnAttribute(Attribute::NoBuiltin))
961+
return nullptr;
962962

963-
return nullptr;
963+
if (!fInfo.isCompatibleSignature(F->getFunctionType()))
964+
return nullptr;
965+
966+
return F;
964967
}
965968

966969
FunctionCallee AMDGPULibFunc::getOrInsertFunction(Module *M,
@@ -969,10 +972,13 @@ FunctionCallee AMDGPULibFunc::getOrInsertFunction(Module *M,
969972
Function *F = dyn_cast_or_null<Function>(
970973
M->getValueSymbolTable().lookup(FuncName));
971974

972-
// check formal with actual types conformance
973-
if (F && !F->isDeclaration() &&
974-
fInfo.isCompatibleSignature(F->getFunctionType()))
975-
return F;
975+
if (F) {
976+
if (F->hasFnAttribute(Attribute::NoBuiltin))
977+
return nullptr;
978+
if (!F->isDeclaration() &&
979+
fInfo.isCompatibleSignature(F->getFunctionType()))
980+
return F;
981+
}
976982

977983
FunctionType *FuncTy = fInfo.getFunctionType(*M);
978984

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-usenative -amdgpu-use-native=all < %s | FileCheck %s
3+
4+
; Verify nobuiltin is respected on a defined function. native_cos is
5+
; marked nobuiltin, but native_sin is not.
6+
7+
define float @_Z10native_sinf(float %x) {
8+
; CHECK-LABEL: define float @_Z10native_sinf
9+
; CHECK-SAME: (float [[X:%.*]]) {
10+
; CHECK-NEXT: [[RESULT:%.*]] = call float asm "
11+
; CHECK-NEXT: ret float [[RESULT]]
12+
;
13+
%result = call float asm "; $0 = native_sin($1)", "=v,v"(float %x)
14+
ret float %result
15+
}
16+
17+
define float @_Z10native_cosf(float %x) nobuiltin {
18+
; CHECK-LABEL: define float @_Z10native_cosf
19+
; CHECK-SAME: (float [[X:%.*]]) #[[ATTR0:[0-9]+]] {
20+
; CHECK-NEXT: [[RESULT:%.*]] = call float asm "
21+
; CHECK-NEXT: ret float [[RESULT]]
22+
;
23+
%result = call float asm "; $0 = native_cos($1)", "=v,v"(float %x)
24+
ret float %result
25+
}
26+
27+
define float @_Z3sinf(float %x) {
28+
; CHECK-LABEL: define float @_Z3sinf
29+
; CHECK-SAME: (float [[X:%.*]]) {
30+
; CHECK-NEXT: [[RESULT:%.*]] = call float asm "
31+
; CHECK-NEXT: ret float [[RESULT]]
32+
;
33+
%result = call float asm "; $0 = sin($1)", "=v,v"(float %x)
34+
ret float %result
35+
}
36+
37+
define float @_Z3cosf(float %x) {
38+
; CHECK-LABEL: define float @_Z3cosf
39+
; CHECK-SAME: (float [[X:%.*]]) {
40+
; CHECK-NEXT: [[RESULT:%.*]] = call float asm "
41+
; CHECK-NEXT: ret float [[RESULT]]
42+
;
43+
%result = call float asm "; $0 = cos($1)", "=v,v"(float %x)
44+
ret float %result
45+
}
46+
47+
define float @call_cos(float %x) {
48+
; CHECK-LABEL: define float @call_cos
49+
; CHECK-SAME: (float [[X:%.*]]) {
50+
; CHECK-NEXT: [[RESULT:%.*]] = call float @_Z3cosf(float [[X]])
51+
; CHECK-NEXT: ret float [[RESULT]]
52+
;
53+
%result = call float @_Z3cosf(float %x)
54+
ret float %result
55+
}
56+
57+
define float @call_sin(float %x) {
58+
; CHECK-LABEL: define float @call_sin
59+
; CHECK-SAME: (float [[X:%.*]]) {
60+
; CHECK-NEXT: [[RESULT:%.*]] = call float @_Z10native_sinf(float [[X]])
61+
; CHECK-NEXT: ret float [[RESULT]]
62+
;
63+
%result = call float @_Z3sinf(float %x)
64+
ret float %result
65+
}

0 commit comments

Comments
 (0)