[llvm] [llvm][opt][Transforms] Preserve AMDGPU atomic metadata (PR #140314)

Alex Voicu via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 08:53:00 PDT 2025


================
@@ -3446,6 +3456,17 @@ static void combineMetadata(Instruction *K, const Instruction *J,
     K->setMetadata(LLVMContext::MD_prof,
                    MDNode::getMergedProfMetadata(KProf, JProf, K, J));
   }
+
+  // Preserve AMDGPU atomic metadata from J, if present. K might already be
+  // carrying this but overwriting should cause no issue.
+  if (K->isAtomic()) {
+    if (auto *JMD = J->getMetadata("amdgpu.no.fine.grained.memory"))
+      K->setMetadata("amdgpu.no.fine.grained.memory", JMD);
+    if (auto *JMD = J->getMetadata("amdgpu.no.remote.memory"))
+      K->setMetadata("amdgpu.no.remote.memory", JMD);
+    if (auto *JMD = J->getMetadata("amdgpu.ignore.denormal.mode"))
+      K->setMetadata("amdgpu.ignore.denormal.mode", JMD);
+  }
----------------
AlexVlx wrote:

I think I misunderstood how these worked / assumed they are per-module global settings. I'll add @yxsamliu to the review since I know you and him worked on this. Intersection seems correct, however I wonder if we should actually prevent sinking / combining altogether if it results in removal of the metadata, since it could incur a pretty significant performance penalty / atomics with different MD aren't really the same instruction to begin with. Thoughts?

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


More information about the llvm-commits mailing list