[PATCH] D156681: AMDGPU: Move check of compatible libcall

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 05:35:29 PDT 2023


arsenm created this revision.
arsenm added reviewers: AMDGPU, rampitec, yaxunl, jhuber6, jmmartinez, dfukalov, vpykhtin.
Herald added subscribers: foad, kerbowa, hiraditya, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D156681

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


Index: llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
+++ llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
@@ -383,6 +383,9 @@
     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(); }
Index: llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp
@@ -945,17 +945,21 @@
   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 @@
     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);
 
Index: llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -601,7 +601,8 @@
     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');


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156681.545610.patch
Type: text/x-patch
Size: 2531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230731/754a0e19/attachment.bin>


More information about the llvm-commits mailing list