Skip to content

Revert "[AMDGPU][LTO] Assume closed world after linking (#105845)" #106889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2024

Conversation

shiltian
Copy link
Contributor

@shiltian shiltian commented Sep 1, 2024

We can't assume closed world even in full LTO post-link stage. It is only true
if we are building a "GPU executable". However, AMDGPU does support "dyamic
library". I'm not aware of any approach to tell if it is relocatable link when
we create the pass. For now let's revert the patch as it is currently breaking things.
We can re-enable it once we can handle it correctly.

We can't assume closed world even in full LTO post-link stage. It is only true
if we are building a "GPU executable". However, AMDGPU does support "dyamic
library". I'm not aware of any approach to tell if it is relocatable link when
we create the pass. For now let's revert the patch. We can re-enable it once we
can handle it correctly.
@shiltian shiltian marked this pull request as ready for review September 1, 2024 06:11
Copy link
Contributor Author

shiltian commented Sep 1, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @shiltian and the rest of your teammates on Graphite Graphite

@shiltian shiltian requested a review from gandhi56 September 1, 2024 06:11
@llvmbot llvmbot added backend:AMDGPU LTO Link time optimization (regular/full LTO or ThinLTO) labels Sep 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 1, 2024

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-lto

Author: Shilei Tian (shiltian)

Changes

We can't assume closed world even in full LTO post-link stage. It is only true
if we are building a "GPU executable". However, AMDGPU does support "dyamic
library". I'm not aware of any approach to tell if it is relocatable link when
we create the pass. For now let's revert the patch. We can re-enable it once we
can handle it correctly.


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

3 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (-4)
  • (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-6)
  • (removed) llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll (-13)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index 0d7b4caa8156ed..72049f0aa6b86e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1065,10 +1065,6 @@ 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 a769bc9e486573..7df39f35478077 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -771,12 +771,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
           PM.addPass(AMDGPUSwLowerLDSPass(*this));
         if (EnableLowerModuleLDS)
           PM.addPass(AMDGPULowerModuleLDSPass(*this));
-
-        if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0) {
-          AMDGPUAttributorOptions Opts;
-          Opts.IsClosedWorld = true;
-          PM.addPass(AMDGPUAttributorPass(*this, Opts));
-        }
+        if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0)
+          PM.addPass(AMDGPUAttributorPass(*this));
       });
 
   PB.registerRegClassFilterParsingCallback(
diff --git a/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
deleted file mode 100644
index 8228f21b56b132..00000000000000
--- a/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll
+++ /dev/null
@@ -1,13 +0,0 @@
-; 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
-; REQUIRES: asserts
-
-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
-}

@shiltian shiltian merged commit 84ed3c2 into main Sep 1, 2024
13 checks passed
@shiltian shiltian deleted the users/shiltian/no-closed-world branch September 1, 2024 13:32
@jhuber6
Copy link
Contributor

jhuber6 commented Sep 1, 2024

Maybe we could modify the AMDGPUAttributor pass to do this by default if there's no external symbols?

@shiltian
Copy link
Contributor Author

shiltian commented Sep 1, 2024

Well, the assumption doesn't hold even w/ externally visible symbols in relocatable link. For example, if we read the callee from an externally visible global variable, that variable could be modified by other "dynamic library" to a function that is not part of this module.

This needs either to be properly handled in AAIndirectCallInfo, or only to set the closed world bit when it is really a closed world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants