brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 567139d Raw
50 lines · plain
1; RUN: opt -S -passes=mergefunc < %s | FileCheck %s -implicit-check-not=funA -implicit-check-not=funC2 3; Replacments should be totally ordered on the function name.4; If we don't do this we  can end up with one module defining a thunk for @funA5; and another module defining a thunk for @funB.6; The problem with this is that the linker could then choose these two stubs7; each of the two modules and we end up with two stubs calling each other.8 9define linkonce i32 @funC(i32 %x, i32 %y) {10  %sum = add i32 %x, %y11  %sum2 = add i32 %x, %sum12  %sum3 = add i32 %x, %sum213  ret i32 %sum314}15 16define linkonce i32 @funB(i32 %x, i32 %y) {17  %sum = add i32 %x, %y18  %sum2 = add i32 %x, %sum19  %sum3 = add i32 %x, %sum220  ret i32 %sum321}22 23define linkonce i32 @funA(i32 %x, i32 %y) {24  %sum = add i32 %x, %y25  %sum2 = add i32 %x, %sum26  %sum3 = add i32 %x, %sum227  ret i32 %sum328}29 30; This creates a use of @funB, preventing -passes=mergefunc from deleting it.31; @funC, however, can safely be deleted as it has no uses, and is discardable32; if unused.33@take_addr_of_funB = global ptr @funB34;.35; CHECK: @take_addr_of_funB = global ptr @funB36;.37; CHECK-LABEL: define private i32 @0(38; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {39; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[X]], [[Y]]40; CHECK-NEXT:    [[SUM2:%.*]] = add i32 [[X]], [[SUM]]41; CHECK-NEXT:    [[SUM3:%.*]] = add i32 [[X]], [[SUM2]]42; CHECK-NEXT:    ret i32 [[SUM3]]43;44;45; CHECK-LABEL: define linkonce i32 @funB(46; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) {47; CHECK-NEXT:    [[TMP3:%.*]] = tail call i32 @0(i32 [[TMP0]], i32 [[TMP1]])48; CHECK-NEXT:    ret i32 [[TMP3]]49;50