[llvm] [AMDGPU] Correctly merge noalias scopes during lowering of LDS data. (PR #131664)

Sirish Pande via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 15:01:02 PDT 2025


================
@@ -1451,7 +1452,17 @@ class AMDGPULowerModuleLDS {
           I->setMetadata(LLVMContext::MD_alias_scope, AS);
 
           MDNode *NA = I->getMetadata(LLVMContext::MD_noalias);
-          NA = (NA ? MDNode::intersect(NA, NoAlias) : NoAlias);
+          // If domain of NoAlias (domain of LDS structure) is different
+          // than existing NA, we need to preserve exising !NoAlias
+          SmallPtrSet<const MDNode *, 16> ExistingDomains, LDSDomains;
+          ScopedNoAlias.collectScopedDomains(NA, ExistingDomains);
+          ScopedNoAlias.collectScopedDomains(NoAlias, LDSDomains);
+          auto Diff = set_difference(ExistingDomains, LDSDomains);
+          if (Diff.empty()) {
+            NA = NA ? MDNode::intersect(NA, NoAlias) : NoAlias;
+          } else {
+            NA = NA ? MDNode::concatenate(NA, NoAlias) : NoAlias;
+          }
----------------
srpande wrote:

I could something like this to be more clear:

```
          auto Intersection = set_intersection(ExistingDomains, LDSDomains);
          if (Intersection.empty()) {
            NA = NA ? MDNode::concatenate(NA, NoAlias) : NoAlias;
          }
          else {
            NA = NA ? MDNode::intersect(NA, NoAlias) : NoAlias;
          }
```
We are only concatenating the existing aliases with LDS aliases if they do not come from the same domain.  The first set opertion is on domain, and depending on that we set operations on alias sets, not on domain sets.

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


More information about the llvm-commits mailing list