xref: /llvm-project/llvm/test/Transforms/MergeFunc/linkonce_odr.ll (revision ee2789001b8558656a13502f0de2c81dcb419430)
1; RUN: opt -S -passes=mergefunc < %s | FileCheck %s -implicit-check-not=funC
2
3; Replacments should be totally ordered on the function name.
4; If we don't do this we  can end up with one module defining a thunk for @funA
5; and another module defining a thunk for @funB.
6;
7; The problem with this is that the linker could then choose these two stubs
8; each of the two modules and we end up with two stubs calling each other.
9
10; CHECK-LABEL: define linkonce_odr i32 @funA
11; CHECK-NEXT:    add
12; CHECK:         ret
13
14; CHECK-LABEL: define linkonce_odr i32 @funB
15; CHECK-NEXT:    tail call i32 @funA(i32 %0, i32 %1)
16; CHECK-NEXT:    ret
17
18define linkonce_odr i32 @funC(i32 %x, i32 %y) {
19  %sum = add i32 %x, %y
20  %sum2 = add i32 %x, %sum
21  %sum3 = add i32 %x, %sum2
22  ret i32 %sum3
23}
24
25define linkonce_odr i32 @funB(i32 %x, i32 %y) {
26  %sum = add i32 %x, %y
27  %sum2 = add i32 %x, %sum
28  %sum3 = add i32 %x, %sum2
29  ret i32 %sum3
30}
31
32define linkonce_odr i32 @funA(i32 %x, i32 %y) {
33  %sum = add i32 %x, %y
34  %sum2 = add i32 %x, %sum
35  %sum3 = add i32 %x, %sum2
36  ret i32 %sum3
37}
38
39; This creates a use of @funB, preventing -passes=mergefunc from deleting it.
40; @funC, however, can safely be deleted as it has no uses, and is discardable
41; if unused.
42@take_addr_of_funB = global ptr @funB
43