[llvm] [AMDGPU] Propagate alias information in AMDGPULowerKernelArguments. (PR #161375)

Leon Clark via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 07:05:40 PST 2025


================
@@ -58,7 +69,114 @@ static BasicBlock::iterator getInsertPt(BasicBlock &BB) {
   return InsPt;
 }
 
-static bool lowerKernelArguments(Function &F, const TargetMachine &TM) {
+static void addAliasScopeMetadata(Function &F, DataLayout const &DL,
+                                  DominatorTree &DT) {
+  // Collect noalias arguments.
+  SmallVector<Argument const *, 4u> NoAliasArgs;
+
+  for (Argument &Arg : F.args())
+    if (Arg.hasNoAliasAttr() && !Arg.use_empty())
+      NoAliasArgs.push_back(&Arg);
+
+  if (NoAliasArgs.empty())
+    return;
+
+  // Add alias scopes for each noalias argument.
+  MDBuilder MDB(F.getContext());
+  DenseMap<Argument const *, MDNode *> NewScopes;
+  MDNode *NewDomain = MDB.createAnonymousAliasScopeDomain(F.getName());
+
+  for (unsigned I = 0u; I < NoAliasArgs.size(); ++I) {
+    Argument const *Arg = NoAliasArgs[I];
+    std::string Name(F.getName());
+    Name += std::string(": argument ") + std::to_string(I);
+    MDNode *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name);
+    NewScopes.insert(std::make_pair(Arg, NewScope));
+  }
+
+  // Iterate over all instructions.
+  for (inst_iterator Inst = inst_begin(F), InstEnd = inst_end(F);
+       Inst != InstEnd; ++Inst) {
+    // If instruction accesses memory, collect its pointer arguments.
+    Instruction *I = &(*Inst);
+    SmallVector<InterestingMemoryOperand, 2u> MemOps;
+    llvm::AMDGPU::getInterestingMemoryOperands(*F.getParent(), I, MemOps);
----------------
PeddleSpam wrote:

I can't find another API for this. There are lots of similar examples to my original code, like in [AMDGPUPerfHintAnalysis.cpp](https://github.com/llvm/llvm-project/blob/a6fa720e72c8c514e97b7cf1fd1043fff52746ac/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp#L118), but they're all static utility functions.

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


More information about the llvm-commits mailing list