[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:03:19 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:

The idea is the set operation on domains. Depending on the result of set operation of domain, we perform set operations on alias set in order to have correct alias sets on loads/store of new elements of LDS structs. 

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


More information about the llvm-commits mailing list