1 ; RUN: opt -S -passes=mergefunc < %s | FileCheck %s -implicit-check-not=funC
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.
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.
10 ; CHECK-LABEL: define linkonce_odr i32 @funA
14 ; CHECK-LABEL: define linkonce_odr i32 @funB
15 ; CHECK-NEXT: tail call i32 @funA(i32 %0, i32 %1)
18 define linkonce_odr i32 @funC(i32 %x, i32 %y) {
20 %sum2 = add i32 %x, %sum
21 %sum3 = add i32 %x, %sum2
25 define linkonce_odr i32 @funB(i32 %x, i32 %y) {
27 %sum2 = add i32 %x, %sum
28 %sum3 = add i32 %x, %sum2
32 define linkonce_odr i32 @funA(i32 %x, i32 %y) {
34 %sum2 = add i32 %x, %sum
35 %sum3 = add i32 %x, %sum2
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
42 @take_addr_of_funB = global ptr @funB