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