[llvm] [AMDGPU] Fix DynLDS causing crash when LowerLDS is run at fullLTO pipeline (PR #96038)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 01:08:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Vigneshwar Jayakumar (VigneshwarJ)

<details>
<summary>Changes</summary>

Direct mapped dynamic LDS is not lowered in the LowerLDSModule pass. Hence
it is not marked with absolute symbol. When lowerLDS pass is rerun in LTO,
compilation fails with assert "cannot mix abs and non-abs LDVs". This patch
adds fix to check if all GVs are absolute or if its non absolute,then
whether it is direct mapped dynLDS, if not fails with the same assert.

Fixes SWDEV-454281


---
Full diff: https://github.com/llvm/llvm-project/pull/96038.diff


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp (+7-2) 
- (modified) llvm/test/CodeGen/AMDGPU/lto-lower-module-lds.ll (+2-1) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
index 04c6e940e6ed6..68f4f6ed101ed 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp
@@ -207,7 +207,9 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
   }
 
   // Verify that we fall into one of 2 cases:
-  //    - All variables are absolute: this is a re-run of the pass
+  //    - All variables are either absolute 
+  //      or direct mapped dynamic LDS that is not lowered.
+  //      this is a re-run of the pass
   //      so we don't have anything to do.
   //    - No variables are absolute.
   std::optional<bool> HasAbsoluteGVs;
@@ -215,8 +217,11 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
     for (auto &[Fn, GVs] : Map) {
       for (auto *GV : GVs) {
         bool IsAbsolute = GV->isAbsoluteSymbolRef();
+        bool IsDirectMapDynLDSGV = AMDGPU::isDynamicLDS(*GV) && DirectMapKernel.contains(Fn);
         if (HasAbsoluteGVs.has_value()) {
-          if (*HasAbsoluteGVs != IsAbsolute) {
+          if (*HasAbsoluteGVs != IsAbsolute ) {
+            if(IsDirectMapDynLDSGV)
+              continue;
             report_fatal_error(
                 "Module cannot mix absolute and non-absolute LDS GVs");
           }
diff --git a/llvm/test/CodeGen/AMDGPU/lto-lower-module-lds.ll b/llvm/test/CodeGen/AMDGPU/lto-lower-module-lds.ll
index f1d946376afe0..c9f4303dfdde3 100644
--- a/llvm/test/CodeGen/AMDGPU/lto-lower-module-lds.ll
+++ b/llvm/test/CodeGen/AMDGPU/lto-lower-module-lds.ll
@@ -39,9 +39,10 @@
 ; CHECK:   Lower uses of LDS variables from non-kernel functions
 
 @lds = internal unnamed_addr addrspace(3) global i32 poison, align 4
-
+ at dynlds = external addrspace(3) global [0 x i32]
 define amdgpu_kernel void @test() {
 entry:
   store i32 1, ptr addrspace(3) @lds
+  store i32 0, ptr addrspace(3) @dynlds
   ret void
 }

``````````

</details>


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


More information about the llvm-commits mailing list