[llvm] f63cdfc - AMDGPU: Move check of compatible libcall

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 13:47:23 PDT 2023


Author: Matt Arsenault
Date: 2023-07-31T16:47:07-04:00
New Revision: f63cdfc4cf87c6ae98e01fbe3e347ea4c882ac05

URL: https://github.com/llvm/llvm-project/commit/f63cdfc4cf87c6ae98e01fbe3e347ea4c882ac05
DIFF: https://github.com/llvm/llvm-project/commit/f63cdfc4cf87c6ae98e01fbe3e347ea4c882ac05.diff

LOG: AMDGPU: Move check of compatible libcall

https://reviews.llvm.org/D156681

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
    llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
    llvm/lib/Target/AMDGPU/AMDGPULibFunc.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index 20395abba2acda..bc916a3ec4a84b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -622,7 +622,8 @@ bool AMDGPULibCalls::fold(CallInst *CI, AliasAnalysis *AA) {
     return false;
 
   // Further check the number of arguments to see if they match.
-  if (CI->arg_size() != FInfo.getNumArgs())
+  // TODO: Check calling convention matches too
+  if (!FInfo.isCompatibleSignature(CI->getFunctionType()))
     return false;
 
   LLVM_DEBUG(dbgs() << "AMDIC: try folding " << *CI << '\n');

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
index 169a242d74e466..741aaaee72f983 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
@@ -945,17 +945,21 @@ std::string AMDGPUMangledLibFunc::getName() const {
   return std::string(OS.str());
 }
 
+bool AMDGPULibFunc::isCompatibleSignature(const FunctionType *FuncTy) const {
+  // TODO: Validate types make sense
+  return !FuncTy->isVarArg() && FuncTy->getNumParams() == getNumArgs();
+}
+
 Function *AMDGPULibFunc::getFunction(Module *M, const AMDGPULibFunc &fInfo) {
   std::string FuncName = fInfo.mangle();
   Function *F = dyn_cast_or_null<Function>(
     M->getValueSymbolTable().lookup(FuncName));
 
   // check formal with actual types conformance
-  if (F && !F->isDeclaration()
-        && !F->isVarArg()
-        && F->arg_size() == fInfo.getNumArgs()) {
+  if (F && !F->isDeclaration() &&
+      fInfo.isCompatibleSignature(F->getFunctionType()))
     return F;
-  }
+
   return nullptr;
 }
 
@@ -966,11 +970,9 @@ FunctionCallee AMDGPULibFunc::getOrInsertFunction(Module *M,
     M->getValueSymbolTable().lookup(FuncName));
 
   // check formal with actual types conformance
-  if (F && !F->isDeclaration()
-        && !F->isVarArg()
-        && F->arg_size() == fInfo.getNumArgs()) {
+  if (F && !F->isDeclaration() &&
+      fInfo.isCompatibleSignature(F->getFunctionType()))
     return F;
-  }
 
   FunctionType *FuncTy = fInfo.getFunctionType(*M);
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.h b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
index bf0fda25b2c0c3..e88963746649ba 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
@@ -383,6 +383,9 @@ class AMDGPULibFunc : public AMDGPULibFuncBase {
     return Impl->parseFuncName(MangledName);
   }
 
+  // Validate the call type matches the expected libfunc type.
+  bool isCompatibleSignature(const FunctionType *FuncTy) const;
+
   /// \return The mangled function name for mangled library functions
   /// and unmangled function name for unmangled library functions.
   std::string mangle() const { return Impl->mangle(); }


        


More information about the llvm-commits mailing list