|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --include-generated-funcs --version 5 |
| 2 | +; RUN: opt -S -passes=mergefunc < %s | FileCheck %s -implicit-check-not=funC |
| 3 | + |
| 4 | +; Replacments should be totally ordered on the function name. |
| 5 | +; If we don't do this we can end up with one module defining a thunk for @funA |
| 6 | +; 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. |
| 9 | + |
| 10 | +define linkonce i32 @funC(i32 %x, i32 %y) { |
| 11 | + %sum = add i32 %x, %y |
| 12 | + %sum2 = add i32 %x, %sum |
| 13 | + %sum3 = add i32 %x, %sum2 |
| 14 | + ret i32 %sum3 |
| 15 | +} |
| 16 | + |
| 17 | +define linkonce i32 @funB(i32 %x, i32 %y) { |
| 18 | + %sum = add i32 %x, %y |
| 19 | + %sum2 = add i32 %x, %sum |
| 20 | + %sum3 = add i32 %x, %sum2 |
| 21 | + ret i32 %sum3 |
| 22 | +} |
| 23 | + |
| 24 | +define linkonce i32 @funA(i32 %x, i32 %y) { |
| 25 | + %sum = add i32 %x, %y |
| 26 | + %sum2 = add i32 %x, %sum |
| 27 | + %sum3 = add i32 %x, %sum2 |
| 28 | + ret i32 %sum3 |
| 29 | +} |
| 30 | + |
| 31 | +; This creates a use of @funB, preventing -passes=mergefunc from deleting it. |
| 32 | +; @funC, however, can safely be deleted as it has no uses, and is discardable |
| 33 | +; if unused. |
| 34 | +@take_addr_of_funB = global ptr @funB |
| 35 | +;. |
| 36 | +; CHECK: @take_addr_of_funB = global ptr @funB |
| 37 | +;. |
| 38 | +; CHECK-LABEL: define private i32 @0( |
| 39 | +; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { |
| 40 | +; CHECK-NEXT: [[SUM:%.*]] = add i32 [[X]], [[Y]] |
| 41 | +; CHECK-NEXT: [[SUM2:%.*]] = add i32 [[X]], [[SUM]] |
| 42 | +; CHECK-NEXT: [[SUM3:%.*]] = add i32 [[X]], [[SUM2]] |
| 43 | +; CHECK-NEXT: ret i32 [[SUM3]] |
| 44 | +; |
| 45 | +; |
| 46 | +; CHECK-LABEL: define linkonce i32 @funC( |
| 47 | +; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { |
| 48 | +; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @[[GLOB0:[0-9]+]](i32 [[TMP0]], i32 [[TMP1]]) |
| 49 | +; CHECK-NEXT: ret i32 [[TMP3]] |
| 50 | +; |
| 51 | +; |
| 52 | +; CHECK-LABEL: define linkonce i32 @funB( |
| 53 | +; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { |
| 54 | +; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 @[[GLOB0]](i32 [[TMP0]], i32 [[TMP1]]) |
| 55 | +; CHECK-NEXT: ret i32 [[TMP3]] |
| 56 | +; |
0 commit comments