[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.
This commit is contained in:
Joseph Huber
2024-11-27 15:55:36 -06:00
parent c6f2d35c4d
commit 4cb4516ae9
3 changed files with 8 additions and 31 deletions

View File

@@ -1539,25 +1539,11 @@ private:
// 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;

View File

@@ -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
@client = internal addrspace(1) global i64 zeroinitializer, align 8
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
@__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
}

View File

@@ -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
@client = internal addrspace(1) global i32 zeroinitializer, align 8
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
@__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() {