1; RUN: opt -S -mergefunc < %s | FileCheck %s 2 3define weak i32 @sum(i32 %x, i32 %y) { 4 %sum = add i32 %x, %y 5 %sum2 = add i32 %sum, %y 6 %sum3 = add i32 %sum2, %y 7 ret i32 %sum3 8} 9 10define weak i32 @add(i32 %x, i32 %y) { 11 %sum = add i32 %x, %y 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 42define 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 47} 48