Skip to content

Commit 4cb4516

Browse files
committed
[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.
1 parent c6f2d35 commit 4cb4516

File tree

3 files changed

+8
-31
lines changed

3 files changed

+8
-31
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,25 +1539,11 @@ struct OpenMPOpt {
15391539
// safely remove it.
15401540
// TODO: This should be somewhere more common in the future.
15411541
if (GlobalVariable *GV = M.getNamedGlobal("__llvm_rpc_client")) {
1542-
if (!GV->getType()->isPointerTy())
1542+
if (GV->getNumUses() >= 1)
15431543
return false;
15441544

1545-
Constant *C = GV->getInitializer();
1546-
if (!C)
1547-
return false;
1548-
1549-
// Check to see if the only user of the RPC client is the external handle.
1550-
GlobalVariable *Client = dyn_cast<GlobalVariable>(C->stripPointerCasts());
1551-
if (!Client || Client->getNumUses() > 1 ||
1552-
Client->user_back() != GV->getInitializer())
1553-
return false;
1554-
1555-
Client->replaceAllUsesWith(PoisonValue::get(Client->getType()));
1556-
Client->eraseFromParent();
1557-
15581545
GV->replaceAllUsesWith(PoisonValue::get(GV->getType()));
15591546
GV->eraseFromParent();
1560-
15611547
return true;
15621548
}
15631549
return false;

llvm/test/Transforms/OpenMP/keep_rpc_client.ll

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
; RUN: opt -S -passes=openmp-opt-postlink < %s | FileCheck %s --check-prefix=POSTLINK
33
; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK
44

5-
@client = internal addrspace(1) global i64 zeroinitializer, align 8
6-
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
5+
@__llvm_rpc_client = internal addrspace(1) global i64 zeroinitializer, align 8
76

87
;.
9-
; POSTLINK: @client = internal addrspace(1) global i64 0, align 8
10-
; POSTLINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
11-
;.
12-
; PRELINK: @client = internal addrspace(1) global i64 0, align 8
13-
; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
8+
; PRELINK: @__llvm_rpc_client = internal addrspace(1) global i64 0, align 8
149
;.
1510
define i64 @a() {
1611
; POSTLINK-LABEL: define {{[^@]+}}@a
1712
; POSTLINK-SAME: () #[[ATTR0:[0-9]+]] {
18-
; POSTLINK-NEXT: [[RETVAL:%.*]] = load i64, ptr addrspace(1) @client, align 8
19-
; POSTLINK-NEXT: ret i64 [[RETVAL]]
13+
; POSTLINK-NEXT: ret i64 0
2014
;
2115
; PRELINK-LABEL: define {{[^@]+}}@a
2216
; PRELINK-SAME: () #[[ATTR0:[0-9]+]] {
23-
; PRELINK-NEXT: [[RETVAL:%.*]] = load i64, ptr addrspace(1) @client, align 8
24-
; PRELINK-NEXT: ret i64 [[RETVAL]]
17+
; PRELINK-NEXT: ret i64 0
2518
;
26-
%retval = load i64, ptr addrspace(1) @client, align 8
19+
%retval = load i64, ptr addrspace(1) @__llvm_rpc_client, align 8
2720
ret i64 %retval
2821
}
2922

llvm/test/Transforms/OpenMP/remove_rpc_client.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
; RUN: opt -S -passes=openmp-opt-postlink < %s | FileCheck %s --check-prefix=POSTLINK
33
; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK
44

5-
@client = internal addrspace(1) global i32 zeroinitializer, align 8
6-
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
5+
@__llvm_rpc_client = internal addrspace(1) global i32 zeroinitializer, align 8
76

87
;.
9-
; PRELINK: @client = internal addrspace(1) global i32 0, align 8
10-
; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
8+
; PRELINK: @__llvm_rpc_client = internal addrspace(1) global i32 0, align 8
119
;.
1210
define void @a() {
1311
; POSTLINK-LABEL: define {{[^@]+}}@a() {

0 commit comments

Comments
 (0)