blob: 825f9054d7b7de53c3766ad1a751ddfaeaa5573f [file] [log] [blame]
Vedant Kumaree10ef72019-01-11 17:56:35 +00001; RUN: opt -S -mergefunc < %s | FileCheck %s -implicit-check-not=funC
Arnold Schwaighofer0302da62015-06-09 00:03:29 +00002
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
Vedant Kumaree10ef72019-01-11 17:56:35 +000018define 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
Arnold Schwaighofer0302da62015-06-09 00:03:29 +000025define 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}
Vedant Kumaree10ef72019-01-11 17:56:35 +000038
39; This creates a use of @funB, preventing -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 i8* bitcast (i32 (i32, i32)* @funB to i8*)