Vedant Kumar | ee10ef7 | 2019-01-11 17:56:35 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -mergefunc < %s | FileCheck %s -implicit-check-not=funC |
Arnold Schwaighofer | 0302da6 | 2015-06-09 00:03:29 +0000 | [diff] [blame] | 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 | |
Vedant Kumar | ee10ef7 | 2019-01-11 17:56:35 +0000 | [diff] [blame] | 18 | define 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 Schwaighofer | 0302da6 | 2015-06-09 00:03:29 +0000 | [diff] [blame] | 25 | define 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 | |
| 32 | define 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 Kumar | ee10ef7 | 2019-01-11 17:56:35 +0000 | [diff] [blame] | 38 | |
| 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*) |