-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MergeFunctions] Preserve symbols used llvm.used/llvm.compiler.used
llvm.used and llvm.compiler.used are often used with inline assembly that refers to a specific symbol so that the symbol is kept through to the linker even though there are no references to it from LLVM IR. This fixes the MergeFunctions pass to preserve references to these symbols in llvm.used/llvm.compiler.used so they are not deleted from the IR. This doesn't prevent these functions from being merged, but guarantees that an alias or thunk with the expected symbol name is kept in the IR. Differential Revision: https://reviews.llvm.org/D127751
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
; RUN: opt -S -mergefunc < %s | FileCheck %s | ||
|
||
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (i32)* @a to i8*)], section "llvm.metadata" | ||
|
||
define internal i32 @a(i32 %a) unnamed_addr { | ||
%b = xor i32 %a, 0 | ||
%c = xor i32 %b, 0 | ||
ret i32 %c | ||
} | ||
|
||
define i32 @b(i32 %a) unnamed_addr { | ||
%b = xor i32 %a, 0 | ||
%c = xor i32 %b, 0 | ||
ret i32 %c | ||
} | ||
|
||
define i32 @c(i32 %a) unnamed_addr { | ||
%b = tail call i32 @a(i32 %a) | ||
ret i32 %b | ||
} | ||
|
||
; CHECK-LABEL: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (i32)* @a to i8*)], section "llvm.metadata" | ||
|
||
; CHECK-LABEL: define i32 @b(i32 %a) unnamed_addr | ||
; CHECK-NEXT: xor | ||
; CHECK-NEXT: xor | ||
; CHECK-NEXT: ret | ||
|
||
; CHECK-LABEL: define i32 @c(i32 %a) unnamed_addr | ||
; CHECK-NEXT: tail call i32 @b(i32 %a) | ||
; CHECK-NEXT: ret | ||
|
||
; CHECK-LABEL: define internal i32 @a(i32 %0) unnamed_addr | ||
; CHECK-NEXT: tail call i32 @b(i32 %0) | ||
; CHECK-NEXT: ret |