[llvm] [LLVM][Tablegen] Add Default arguments support for Intrinsics in TableGen (PR #198557)

Varad Rahul Kamthe via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 06:44:54 PDT 2026


================
@@ -4983,6 +5013,60 @@ static Value *upgradeConvertIntrinsicCall(StringRef Name, CallBase *CI,
   return nullptr;
 }
 
+static bool upgradeIntrinsicCallWithDefaultArgs(CallBase *CI, Function *NewFn,
+                                                IRBuilder<> &Builder) {
+  Intrinsic::ID IID = NewFn->getIntrinsicID();
+
+  // Fast path: this intrinsic has no default args in the table.
+  if (!Intrinsic::hasDefaultArgs(IID))
+    return false;
+
+  unsigned OldArgCount = CI->arg_size();
+  unsigned NewArgCount = NewFn->arg_size();
+
+  // If the caller already supplied all arguments (or more), nothing to do.
+  // This mirrors C++ semantics: an explicitly-passed value is never overridden.
+  if (OldArgCount >= NewArgCount)
+    return false;
+
+  // Start with the existing arguments from the old call.
+  SmallVector<Value *, 8> NewArgs(CI->args());
+
+  // Fill in each missing trailing argument from the table.
+  FunctionType *NewFT = NewFn->getFunctionType();
+  for (unsigned Idx = OldArgCount; Idx < NewArgCount; ++Idx) {
+    std::optional<int64_t> DefaultVal = Intrinsic::getDefaultArgValue(IID, Idx);
----------------
varadk27 wrote:

Done. Replaced `getDefaultArgValue `with `getAllDefaultArgValues` returning `std::pair<unsigned, ArrayRef<int64_t>>`. Thanks!

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


More information about the llvm-commits mailing list