[llvm] Add AMDGPU metadata to copyMetadataForLoad() (PR #110720)

Krzysztof Drewniak via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 11:32:59 PDT 2024


https://github.com/krzysz00 created https://github.com/llvm/llvm-project/pull/110720

There's some AMDGPU-specific metadata that should also be propagated when copyMetadataForLoad() is used instead of a copyMetadata().

The amdgpu.last.use metadata is a form of nontemporal hint that should be preserved.

amdgpu.no.remote.memory and amdgpu.no.fine.grained.memory currently only enable certain atomic instructions that aren't always safe on some targets, but they might need to be applied to atomic loads in the future.

>From 38d5c16a8e8f3a01671c0af812309bcb01a3cb86 Mon Sep 17 00:00:00 2001
From: Krzysztof Drewniak <Krzysztof.Drewniak at amd.com>
Date: Tue, 1 Oct 2024 18:27:43 +0000
Subject: [PATCH] Add AMDGPU metadata to copyMetadataForLoad()

There's some AMDGPU-specific metadata that should also be propagated
when copyMetadataForLoad() is used instead of a copyMetadata().

The amdgpu.last.use metadata is a form of nontemporal hint that should
be preserved.

amdgpu.no.remote.memory and amdgpu.no.fine.grained.memory currently
only enable certain atomic instructions that aren't always safe on
some targets, but they might need to be applied to atomic loads in the
future.
---
 llvm/lib/Transforms/Utils/Local.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index cfe40f91f9a5df..972524c10a71d5 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3445,6 +3445,8 @@ void llvm::copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source) {
   MDBuilder MDB(Dest.getContext());
   Type *NewType = Dest.getType();
   const DataLayout &DL = Source.getDataLayout();
+  LLVMContext &Ctx = Dest.getContext();
+
   for (const auto &MDPair : MD) {
     unsigned ID = MDPair.first;
     MDNode *N = MDPair.second;
@@ -3488,6 +3490,14 @@ void llvm::copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source) {
       copyRangeMetadata(DL, Source, N, Dest);
       break;
     }
+    // Extended last-use / nontemporal hint on AMD GPUs
+    if (ID == Ctx.getMDKindID("amdpu.last.use"))
+      Dest.setMetadata(ID, N);
+    // Currently only relevant to atomics
+    else if (ID == Ctx.getMDKindID("amdgpu.no.remote.memory"))
+      Dest.setMetadata(ID, N);
+    else if (ID == Ctx.getMDKindID("amdgpu.no.fine.grained.memory"))
+      Dest.setMetadata(ID, N);
   }
 }
 



More information about the llvm-commits mailing list