Arnold Schwaighofer | 7e22627 | 2015-06-09 18:19:17 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -mergefunc < %s | FileCheck %s |
Nick Lewycky | 25675ac | 2009-06-12 15:56:56 +0000 | [diff] [blame] | 2 | |
| 3 | define weak i32 @sum(i32 %x, i32 %y) { |
| 4 | %sum = add i32 %x, %y |
Arnold Schwaighofer | 7e22627 | 2015-06-09 18:19:17 +0000 | [diff] [blame] | 5 | %sum2 = add i32 %sum, %y |
| 6 | %sum3 = add i32 %sum2, %y |
| 7 | ret i32 %sum3 |
Nick Lewycky | 25675ac | 2009-06-12 15:56:56 +0000 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | define weak i32 @add(i32 %x, i32 %y) { |
| 11 | %sum = add i32 %x, %y |
Arnold Schwaighofer | 7e22627 | 2015-06-09 18:19:17 +0000 | [diff] [blame] | 12 | %sum2 = add i32 %sum, %y |
| 13 | %sum3 = add i32 %sum2, %y |
| 14 | ret i32 %sum3 |
| 15 | } |
| 16 | |
| 17 | ; Don't replace a weak function use by another equivalent function. We don't |
| 18 | ; know whether the symbol that will ulitmately be linked is equivalent - we |
| 19 | ; don't know that the weak definition is the definitive definition or whether it |
| 20 | ; will be overriden by a stronger definition). |
| 21 | |
| 22 | ; CHECK-LABEL: define private i32 @0 |
| 23 | ; CHECK: add i32 |
| 24 | ; CHECK: add i32 |
| 25 | ; CHECK: add i32 |
| 26 | ; CHECK: ret |
| 27 | |
| 28 | ; CHECK-LABEL: define i32 @use_weak |
| 29 | ; CHECK: call i32 @add |
| 30 | ; CHECK: call i32 @sum |
| 31 | ; CHECK: ret |
| 32 | |
| 33 | ; CHECK-LABEL: define weak i32 @sum |
| 34 | ; CHECK: tail call i32 @0 |
| 35 | ; CHECK: ret |
| 36 | |
| 37 | ; CHECK-LABEL: define weak i32 @add |
| 38 | ; CHECK: tail call i32 @0 |
| 39 | ; CHECK: ret |
| 40 | |
| 41 | |
| 42 | define i32 @use_weak(i32 %a, i32 %b) { |
| 43 | %res = call i32 @add(i32 %a, i32 %b) |
| 44 | %res2 = call i32 @sum(i32 %a, i32 %b) |
| 45 | %res3 = add i32 %res, %res2 |
| 46 | ret i32 %res3 |
Nick Lewycky | 25675ac | 2009-06-12 15:56:56 +0000 | [diff] [blame] | 47 | } |