[llvm] [AMDGPU][NewPass] Attempt to promote uniform ptr arguments to inreg (PR #210410)

Akash Dutta via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 10:56:31 PDT 2026


================
@@ -0,0 +1,144 @@
+//===-- AMDGPUPromoteUniformArgs.cpp --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Promote pointer arguments of internal callees to \c inreg when every visible
+// call-site operand is trivially uniform per \c GCNTTIImpl::isAlwaysUniform
+// (queried through TTI). Arg-chain propagation, private guards, and full
+// \c UniformityInfo are planned follow-ups; see
+// \c AMDGPUPromoteUniformArgs.cpp.advanced for a more complete prototype.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPU.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Analysis.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "amdgpu-promote-uniform-args"
+
+STATISTIC(NumPromotedInRegArgs,
+          "Number of uniform pointer arguments promoted to inreg");
+STATISTIC(NumPromotedInRegFuncs,
+          "Number of functions with a promoted uniform pointer argument");
+
+static cl::opt<bool> EnablePromoteUniformArgs(
+    "amdgpu-enable-promote-uniform-args", cl::Hidden, cl::init(true),
+    cl::desc("Promote provably uniform internal pointer arguments to inreg"));
+
+namespace {
+
+static bool canPromoteArgToInReg(const Argument &A) {
+  if (!A.getType()->isPointerTy() || A.hasInRegAttr())
+    return false;
+  if (A.hasPointeeInMemoryValueAttr() || A.hasNestAttr() ||
+      A.hasReturnedAttr() || A.hasSwiftSelfAttr() || A.hasSwiftErrorAttr() ||
+      A.hasAttribute(Attribute::SwiftAsync))
+    return false;
+  return !A.hasAttribute("amdgpu-hidden-argument");
+}
+
+static bool isEligibleInRegUniformCallee(const Function &F) {
+  if (F.isDeclaration() || F.isVarArg() || F.hasOptNone())
+    return false;
+  if (!F.hasLocalLinkage() || F.hasAddressTaken())
+    return false;
+  switch (F.getCallingConv()) {
+  case CallingConv::C:
+  case CallingConv::Fast:
+    break;
+  default:
+    return false;
+  }
+  for (const User *U : F.users()) {
+    const auto *CB = dyn_cast<CallBase>(U);
+    if (!CB || CB->getCalledFunction() != &F)
----------------
akadutta wrote:

F can appear as a call operand (call @sink(ptr @F)), so getCalledFunction() != &F rejects those uses

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


More information about the llvm-commits mailing list