[llvm] [LLVM][AutoUpgrade] Support default args on undeclared multi-call upgrades (PR #216246)

Dharuni R Acharya via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 04:20:08 PDT 2026


================
@@ -1467,33 +1467,35 @@ static bool convertIntrinsicValidType(StringRef Name,
   return false;
 }
 
-static bool upgradeIntrinsicDeclWithDefaultArgs(Function *F, Function *&NewFn) {
-  Intrinsic::ID IID = Intrinsic::lookupIntrinsicID(F->getName());
-  if (IID == Intrinsic::not_intrinsic)
-    return false;
-
+static bool getDefaultArgUpgradeInfo(Function *F, Intrinsic::ID IID,
+                                     unsigned &FullArgCount) {
   auto [FirstDefault, Defaults] = Intrinsic::getAllDefaultArgValues(IID);
   if (Defaults.empty())
     return false;
 
-  // Overloaded intrinsics are out of scope for the default-arg feature
-  // and will be supported in a follow-up.
   if (Intrinsic::isOverloaded(IID))
     return false;
 
-  // Get the canonical full declaration for this intrinsic.
-  Function *FullDecl = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
+  FullArgCount = FirstDefault + Defaults.size();
 
-  // If the existing declaration already has all args, nothing to upgrade
-  if (F->arg_size() >= FullDecl->arg_size())
+  // Only trailing default arguments can be missing.
+  if (F->arg_size() < FirstDefault || F->arg_size() >= FullArgCount)
     return false;
 
-  // Defaults are a contiguous trailing block, so checking the first missing
-  // argument is enough.
-  if (F->arg_size() < FirstDefault)
+  return true;
+}
+
+static bool upgradeIntrinsicWithDefaultArgs(Function *F, Function *&NewFn) {
+  Intrinsic::ID IID = F->getIntrinsicID();
+
+  unsigned FullArgCount;
+  if (!getDefaultArgUpgradeInfo(F, IID, FullArgCount))
----------------
DharuniRAcharya wrote:

Makes sense. Updated in the latest revision!

https://github.com/llvm/llvm-project/pull/216246


More information about the llvm-commits mailing list