Skip to content

Commit 82404e3

Browse files
authored
[CGData][GMF] Skip merging unnamed functions (#148995)
Skip merging unnamed functions to fix an assertion issue, since unnamed functions would otherwise receive the same merged name -- https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/GlobalMergeFunctions.cpp#L191
1 parent 1754a7d commit 82404e3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm/lib/CodeGen/GlobalMergeFunctions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ bool isEligibleFunction(Function *F) {
9595
if (F->getCallingConv() == CallingConv::SwiftTail)
9696
return false;
9797

98+
// Unnamed functions are skipped for simplicity.
99+
if (!F->hasName())
100+
return false;
101+
98102
// If function contains callsites with musttail, if we merge
99103
// it, the merged function will have the musttail callsite, but
100104
// the number of parameters can change, thus the parameter count
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; This test checks if two similar functions, @0 and @1, are not merged as they are unnamed.
2+
3+
; RUN: opt -mtriple=arm64-apple-darwin -S --passes=global-merge-func %s | FileCheck %s
4+
; RUN: llc -mtriple=arm64-apple-darwin -enable-global-merge-func=true < %s | FileCheck %s
5+
6+
; CHECK-NOT: .Tgm
7+
8+
@g = external local_unnamed_addr global [0 x i32], align 4
9+
@g1 = external global i32, align 4
10+
@g2 = external global i32, align 4
11+
12+
define i32 @0(i32 %a) {
13+
entry:
14+
%idxprom = sext i32 %a to i64
15+
%arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i64 0, i64 %idxprom
16+
%0 = load i32, i32* %arrayidx, align 4
17+
%1 = load volatile i32, i32* @g1, align 4
18+
%mul = mul nsw i32 %1, %0
19+
%add = add nsw i32 %mul, 1
20+
ret i32 %add
21+
}
22+
23+
define i32 @1(i32 %a) {
24+
entry:
25+
%idxprom = sext i32 %a to i64
26+
%arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @g, i64 0, i64 %idxprom
27+
%0 = load i32, i32* %arrayidx, align 4
28+
%1 = load volatile i32, i32* @g2, align 4
29+
%mul = mul nsw i32 %1, %0
30+
%add = add nsw i32 %mul, 1
31+
ret i32 %add
32+
}

0 commit comments

Comments
 (0)