[llvm] Revert "Revert "[AMDGPU][LTO] Assume closed world after linking (#105845)" (#106000)" (PR #106001)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 25 12:03:19 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-lto

Author: Anshil Gandhi (gandhi56)

<details>
<summary>Changes</summary>

This reverts commit 4b6c064dd124c70ff163411dff120c6174e0e022.

Add a requirement for an amdgpu target in the test.


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


3 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+4) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+6-2) 
- (added) llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll (+12) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index d65e0ae92308e6..81932cc2c3c3bc 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1066,6 +1066,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
 
   Attributor A(Functions, InfoCache, AC);
 
+  LLVM_DEBUG(dbgs() << "Module " << M.getName() << " is "
+                    << (AC.IsClosedWorldModule ? "" : "not ")
+                    << "assumed to be a closed world.\n");
+
   for (Function &F : M) {
     if (F.isIntrinsic())
       continue;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 7ac7b3315bb972..307774ea3da9eb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -760,8 +760,12 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
         // module is partitioned for codegen.
         if (EnableLowerModuleLDS)
           PM.addPass(AMDGPULowerModuleLDSPass(*this));
-        if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0)
-          PM.addPass(AMDGPUAttributorPass(*this));
+
+        if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0) {
+          AMDGPUAttributorOptions Opts;
+          Opts.IsClosedWorld = true;
+          PM.addPass(AMDGPUAttributorPass(*this, Opts));
+        }
       });
 
   PB.registerRegClassFilterParsingCallback(
diff --git a/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
new file mode 100644
index 00000000000000..42640f94537640
--- /dev/null
+++ b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
@@ -0,0 +1,12 @@
+; RUN: opt -O3 -debug-only=amdgpu-attributor -S -o - %s 2>&1 | FileCheck %s --check-prefix=PRE-LINK
+; RUN: opt -passes="lto<O3>" -debug-only=amdgpu-attributor -S -o - %s 2>&1 | FileCheck %s --check-prefix=POST-LINK
+
+; REQUIRES: amdgpu-registered-target
+
+target triple = "amdgcn-amd-amdhsa"
+
+; PRE-LINK: Module {{.*}} is not assumed to be a closed world.
+; POST-LINK: Module {{.*}} is assumed to be a closed world.
+define hidden noundef i32 @_Z3foov() {
+  ret i32 1
+}

``````````

</details>


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


More information about the llvm-commits mailing list