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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 13:04:56 PDT 2026


================
@@ -0,0 +1,136 @@
+//===-- 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 scalar and pointer arguments of internal callees to \c inreg when
+// every visible call-site operand is trivially uniform: a constant, an
+// argument passed in an SGPR, or an always-uniform intrinsic in the same
+// block as the call. Vectors are not promoted.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPU.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/IR/Analysis.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "amdgpu-promote-uniform-args"
+
+STATISTIC(NumPromotedInRegArgs,
+          "Number of uniform arguments promoted to inreg");
+STATISTIC(NumPromotedInRegFuncs,
+          "Number of functions with a promoted uniform argument");
+
+namespace {
+
+static bool canPromoteArgToInReg(const Argument &A) {
+  Type *Ty = A.getType();
+  if (!(Ty->isIntOrPtrTy() || Ty->isFloatingPointTy()) || A.hasInRegAttr())
+    return false;
+  // inreg is mutually exclusive with byval, inalloca, preallocated, byref,
+  // sret, and nest. The first five are covered by hasPointeeInMemoryValueAttr.
+  if (A.hasPointeeInMemoryValueAttr() || A.hasNestAttr())
+    return false;
+  return !A.hasAttribute("amdgpu-hidden-argument");
+}
+
+static bool collectDirectCallSites(Function &F,
+                                   SmallVectorImpl<CallBase *> &Calls) {
+  if (F.isDeclaration() || F.isVarArg() || !F.canChangeSignature())
+    return false;
+  if (!F.hasLocalLinkage())
+    return false;
+  switch (F.getCallingConv()) {
+  case CallingConv::C:
+  case CallingConv::Fast:
+    break;
----------------
arsenm wrote:

Shouldn't limit the CCs, e.g. should also cover amdgpu_func and coldcc. Don't see a reason to maintain a new switch 

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


More information about the llvm-commits mailing list