[llvm] 4cb4516 - [OpenMP] Fix RPC client not being optimized out after changes

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 13:56:53 PST 2024


Author: Joseph Huber
Date: 2024-11-27T15:56:23-06:00
New Revision: 4cb4516ae9ae2f267ec755ed0ec6b671fe6747b8

URL: https://github.com/llvm/llvm-project/commit/4cb4516ae9ae2f267ec755ed0ec6b671fe6747b8
DIFF: https://github.com/llvm/llvm-project/commit/4cb4516ae9ae2f267ec755ed0ec6b671fe6747b8.diff

LOG: [OpenMP] Fix RPC client not being optimized out after changes

Summary:
I forgot that this check deliberately looked through the indirection I
removed. Fix it to just check if the symbol has no users.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/OpenMPOpt.cpp
    llvm/test/Transforms/OpenMP/keep_rpc_client.ll
    llvm/test/Transforms/OpenMP/remove_rpc_client.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 6671fa84c33867..b40ab357670b86 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1539,25 +1539,11 @@ struct OpenMPOpt {
     // safely remove it.
     // TODO: This should be somewhere more common in the future.
     if (GlobalVariable *GV = M.getNamedGlobal("__llvm_rpc_client")) {
-      if (!GV->getType()->isPointerTy())
+      if (GV->getNumUses() >= 1)
         return false;
 
-      Constant *C = GV->getInitializer();
-      if (!C)
-        return false;
-
-      // Check to see if the only user of the RPC client is the external handle.
-      GlobalVariable *Client = dyn_cast<GlobalVariable>(C->stripPointerCasts());
-      if (!Client || Client->getNumUses() > 1 ||
-          Client->user_back() != GV->getInitializer())
-        return false;
-
-      Client->replaceAllUsesWith(PoisonValue::get(Client->getType()));
-      Client->eraseFromParent();
-
       GV->replaceAllUsesWith(PoisonValue::get(GV->getType()));
       GV->eraseFromParent();
-
       return true;
     }
     return false;

diff  --git a/llvm/test/Transforms/OpenMP/keep_rpc_client.ll b/llvm/test/Transforms/OpenMP/keep_rpc_client.ll
index d6799e882cbb36..b1c40e852a5e56 100644
--- a/llvm/test/Transforms/OpenMP/keep_rpc_client.ll
+++ b/llvm/test/Transforms/OpenMP/keep_rpc_client.ll
@@ -2,28 +2,21 @@
 ; RUN: opt -S -passes=openmp-opt-postlink < %s | FileCheck %s --check-prefix=POSTLINK
 ; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK
 
- at client = internal addrspace(1) global i64 zeroinitializer, align 8
- at __llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
+ at __llvm_rpc_client = internal addrspace(1) global i64 zeroinitializer, align 8
 
 ;.
-; POSTLINK: @client = internal addrspace(1) global i64 0, align 8
-; POSTLINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
-;.
-; PRELINK: @client = internal addrspace(1) global i64 0, align 8
-; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
+; PRELINK: @__llvm_rpc_client = internal addrspace(1) global i64 0, align 8
 ;.
 define i64 @a() {
 ; POSTLINK-LABEL: define {{[^@]+}}@a
 ; POSTLINK-SAME: () #[[ATTR0:[0-9]+]] {
-; POSTLINK-NEXT:    [[RETVAL:%.*]] = load i64, ptr addrspace(1) @client, align 8
-; POSTLINK-NEXT:    ret i64 [[RETVAL]]
+; POSTLINK-NEXT:    ret i64 0
 ;
 ; PRELINK-LABEL: define {{[^@]+}}@a
 ; PRELINK-SAME: () #[[ATTR0:[0-9]+]] {
-; PRELINK-NEXT:    [[RETVAL:%.*]] = load i64, ptr addrspace(1) @client, align 8
-; PRELINK-NEXT:    ret i64 [[RETVAL]]
+; PRELINK-NEXT:    ret i64 0
 ;
-  %retval = load i64, ptr addrspace(1) @client, align 8
+  %retval = load i64, ptr addrspace(1) @__llvm_rpc_client, align 8
   ret i64 %retval
 }
 

diff  --git a/llvm/test/Transforms/OpenMP/remove_rpc_client.ll b/llvm/test/Transforms/OpenMP/remove_rpc_client.ll
index 319d2726d99644..29f6c6b12e4ceb 100644
--- a/llvm/test/Transforms/OpenMP/remove_rpc_client.ll
+++ b/llvm/test/Transforms/OpenMP/remove_rpc_client.ll
@@ -2,12 +2,10 @@
 ; RUN: opt -S -passes=openmp-opt-postlink < %s | FileCheck %s --check-prefix=POSTLINK
 ; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK
 
- at client = internal addrspace(1) global i32 zeroinitializer, align 8
- at __llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
+ at __llvm_rpc_client = internal addrspace(1) global i32 zeroinitializer, align 8
 
 ;.
-; PRELINK: @client = internal addrspace(1) global i32 0, align 8
-; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
+; PRELINK: @__llvm_rpc_client = internal addrspace(1) global i32 0, align 8
 ;.
 define void @a() {
 ; POSTLINK-LABEL: define {{[^@]+}}@a() {


        


More information about the llvm-commits mailing list