1f38f99bdSRoman Lebedev; RUN: opt -S -passes=mergefunc < %s | FileCheck %s -implicit-check-not=funC 2cee313d2SEric Christopher 3cee313d2SEric Christopher; Replacments should be totally ordered on the function name. 4cee313d2SEric Christopher; If we don't do this we can end up with one module defining a thunk for @funA 5cee313d2SEric Christopher; and another module defining a thunk for @funB. 6cee313d2SEric Christopher; 7cee313d2SEric Christopher; The problem with this is that the linker could then choose these two stubs 8cee313d2SEric Christopher; each of the two modules and we end up with two stubs calling each other. 9cee313d2SEric Christopher 10cee313d2SEric Christopher; CHECK-LABEL: define linkonce_odr i32 @funA 11cee313d2SEric Christopher; CHECK-NEXT: add 12cee313d2SEric Christopher; CHECK: ret 13cee313d2SEric Christopher 14cee313d2SEric Christopher; CHECK-LABEL: define linkonce_odr i32 @funB 15cee313d2SEric Christopher; CHECK-NEXT: tail call i32 @funA(i32 %0, i32 %1) 16cee313d2SEric Christopher; CHECK-NEXT: ret 17cee313d2SEric Christopher 18cee313d2SEric Christopherdefine linkonce_odr i32 @funC(i32 %x, i32 %y) { 19cee313d2SEric Christopher %sum = add i32 %x, %y 20cee313d2SEric Christopher %sum2 = add i32 %x, %sum 21cee313d2SEric Christopher %sum3 = add i32 %x, %sum2 22cee313d2SEric Christopher ret i32 %sum3 23cee313d2SEric Christopher} 24cee313d2SEric Christopher 25cee313d2SEric Christopherdefine linkonce_odr i32 @funB(i32 %x, i32 %y) { 26cee313d2SEric Christopher %sum = add i32 %x, %y 27cee313d2SEric Christopher %sum2 = add i32 %x, %sum 28cee313d2SEric Christopher %sum3 = add i32 %x, %sum2 29cee313d2SEric Christopher ret i32 %sum3 30cee313d2SEric Christopher} 31cee313d2SEric Christopher 32cee313d2SEric Christopherdefine linkonce_odr i32 @funA(i32 %x, i32 %y) { 33cee313d2SEric Christopher %sum = add i32 %x, %y 34cee313d2SEric Christopher %sum2 = add i32 %x, %sum 35cee313d2SEric Christopher %sum3 = add i32 %x, %sum2 36cee313d2SEric Christopher ret i32 %sum3 37cee313d2SEric Christopher} 38cee313d2SEric Christopher 39f38f99bdSRoman Lebedev; This creates a use of @funB, preventing -passes=mergefunc from deleting it. 40cee313d2SEric Christopher; @funC, however, can safely be deleted as it has no uses, and is discardable 41cee313d2SEric Christopher; if unused. 42*ee278900SNikita Popov@take_addr_of_funB = global ptr @funB 43