1*dc85d526SKyungwoo Lee; This test checks if we can outline a singleton instance (i.e., an instance that 2*dc85d526SKyungwoo Lee; does not repeat) through two codegen rounds. The first round identifies a local 3*dc85d526SKyungwoo Lee; outlining instance within thin-two.ll, which is then encoded in the resulting 4*dc85d526SKyungwoo Lee; object file and merged into the codegen data summary. 5*dc85d526SKyungwoo Lee; The second round utilizes the merged codegen data to optimistically outline a 6*dc85d526SKyungwoo Lee; singleton instance in thin-one.ll. 7*dc85d526SKyungwoo Lee; Note that this global outlining creates a unique instance for each sequence 8*dc85d526SKyungwoo Lee; without directly sharing identical functions for correctness. 9*dc85d526SKyungwoo Lee; Actual code size reductions occur at link time through identical code folding. 10*dc85d526SKyungwoo Lee; When both thinlto and lto modules are compiled, the lto module is processed 11*dc85d526SKyungwoo Lee; independently, without relying on the merged codegen data. In this case, 12*dc85d526SKyungwoo Lee; the identical code sequences are directly replaced by a common outlined function. 13*dc85d526SKyungwoo Lee 14*dc85d526SKyungwoo Lee; RUN: split-file %s %t 15*dc85d526SKyungwoo Lee 16*dc85d526SKyungwoo Lee; Verify each outlining instance is singleton with the global outlining for thinlto. 17*dc85d526SKyungwoo Lee; They will be identical, which can be folded by the linker with ICF. 18*dc85d526SKyungwoo Lee; RUN: opt -module-summary %t/thin-one.ll -o %t/thin-one.bc 19*dc85d526SKyungwoo Lee; RUN: opt -module-summary %t/thin-two.ll -o %t/thin-two.bc 20*dc85d526SKyungwoo Lee; RUN: llvm-lto2 run %t/thin-one.bc %t/thin-two.bc -o %t/thinlto \ 21*dc85d526SKyungwoo Lee; RUN: -r %t/thin-one.bc,_f3,px -r %t/thin-one.bc,_g,x \ 22*dc85d526SKyungwoo Lee; RUN: -r %t/thin-two.bc,_f1,px -r %t/thin-two.bc,_f2,px -r %t/thin-two.bc,_g,x \ 23*dc85d526SKyungwoo Lee; RUN: -codegen-data-thinlto-two-rounds 24*dc85d526SKyungwoo Lee 25*dc85d526SKyungwoo Lee; thin-one.ll will have one outlining instance itself (matched in the global outlined hash tree) 26*dc85d526SKyungwoo Lee; RUN: llvm-objdump -d %t/thinlto.1 | FileCheck %s --check-prefix=THINLTO-1 27*dc85d526SKyungwoo Lee; THINLTO-1: _OUTLINED_FUNCTION{{.*}}>: 28*dc85d526SKyungwoo Lee; THINLTO-1-NEXT: mov 29*dc85d526SKyungwoo Lee; THINLTO-1-NEXT: mov 30*dc85d526SKyungwoo Lee; THINLTO-1-NEXT: b 31*dc85d526SKyungwoo Lee 32*dc85d526SKyungwoo Lee; thin-two.ll will have two respective outlining instances (matched in the global outlined hash tree) 33*dc85d526SKyungwoo Lee; RUN: llvm-objdump -d %t/thinlto.2 | FileCheck %s --check-prefix=THINLTO-2 34*dc85d526SKyungwoo Lee; THINLTO-2: _OUTLINED_FUNCTION{{.*}}>: 35*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: mov 36*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: mov 37*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: b 38*dc85d526SKyungwoo Lee; THINLTO-2: _OUTLINED_FUNCTION{{.*}}>: 39*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: mov 40*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: mov 41*dc85d526SKyungwoo Lee; THINLTO-2-NEXT: b 42*dc85d526SKyungwoo Lee 43*dc85d526SKyungwoo Lee; Now add a lto module to the above thinlto modules. 44*dc85d526SKyungwoo Lee; Verify the lto module is optimized independent of the global outlining for thinlto. 45*dc85d526SKyungwoo Lee; RUN: opt %t/lto.ll -o %t/lto.bc 46*dc85d526SKyungwoo Lee; RUN: llvm-lto2 run %t/thin-one.bc %t/thin-two.bc %t/lto.bc -o %t/out \ 47*dc85d526SKyungwoo Lee; RUN: -r %t/thin-one.bc,_f3,px -r %t/thin-one.bc,_g,x \ 48*dc85d526SKyungwoo Lee; RUN: -r %t/thin-two.bc,_f1,px -r %t/thin-two.bc,_f2,px -r %t/thin-two.bc,_g,x \ 49*dc85d526SKyungwoo Lee; RUN: -r %t/lto.bc,_f4,px -r %t/lto.bc,_f5,px -r %t/lto.bc,_f6,px -r %t/lto.bc,_g,x \ 50*dc85d526SKyungwoo Lee; RUN: -codegen-data-thinlto-two-rounds 51*dc85d526SKyungwoo Lee 52*dc85d526SKyungwoo Lee; lto.ll will have one shared outlining instance within the lto module itself (no global outlining). 53*dc85d526SKyungwoo Lee; RUN: llvm-objdump -d %t/out.0 | FileCheck %s --check-prefix=LTO-0 54*dc85d526SKyungwoo Lee; LTO-0: _OUTLINED_FUNCTION{{.*}}>: 55*dc85d526SKyungwoo Lee; LTO-0-NEXT: mov 56*dc85d526SKyungwoo Lee; LTO-0-NEXT: b 57*dc85d526SKyungwoo Lee; LTO-0-NOT: _OUTLINED_FUNCTION{{.*}}>: 58*dc85d526SKyungwoo Lee 59*dc85d526SKyungwoo Lee; thin-one.ll will have one outlining instance (matched in the global outlined hash tree) 60*dc85d526SKyungwoo Lee; RUN: llvm-objdump -d %t/out.1 | FileCheck %s --check-prefix=THINLTO-1 61*dc85d526SKyungwoo Lee 62*dc85d526SKyungwoo Lee; thin-two.ll will have two outlining instances (matched in the global outlined hash tree) 63*dc85d526SKyungwoo Lee; RUN: llvm-objdump -d %t/out.2 | FileCheck %s --check-prefix=THINLTO-2 64*dc85d526SKyungwoo Lee 65*dc85d526SKyungwoo Lee;--- thin-one.ll 66*dc85d526SKyungwoo Leetarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 67*dc85d526SKyungwoo Leetarget triple = "arm64-apple-darwin" 68*dc85d526SKyungwoo Lee 69*dc85d526SKyungwoo Leedeclare i32 @g(i32, i32, i32) 70*dc85d526SKyungwoo Leedefine i32 @f3() minsize { 71*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 30, i32 1, i32 2); 72*dc85d526SKyungwoo Lee ret i32 %1 73*dc85d526SKyungwoo Lee} 74*dc85d526SKyungwoo Lee 75*dc85d526SKyungwoo Lee;--- thin-two.ll 76*dc85d526SKyungwoo Leetarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 77*dc85d526SKyungwoo Leetarget triple = "arm64-apple-darwin" 78*dc85d526SKyungwoo Lee 79*dc85d526SKyungwoo Leedeclare i32 @g(i32, i32, i32) 80*dc85d526SKyungwoo Leedefine i32 @f1() minsize { 81*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 10, i32 1, i32 2); 82*dc85d526SKyungwoo Lee ret i32 %1 83*dc85d526SKyungwoo Lee} 84*dc85d526SKyungwoo Leedefine i32 @f2() minsize { 85*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 20, i32 1, i32 2); 86*dc85d526SKyungwoo Lee ret i32 %1 87*dc85d526SKyungwoo Lee} 88*dc85d526SKyungwoo Lee 89*dc85d526SKyungwoo Lee;--- lto.ll 90*dc85d526SKyungwoo Leetarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 91*dc85d526SKyungwoo Leetarget triple = "arm64-apple-darwin" 92*dc85d526SKyungwoo Lee 93*dc85d526SKyungwoo Leedeclare i32 @g(i32, i32, i32) 94*dc85d526SKyungwoo Leedefine i32 @f4() minsize { 95*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 10, i32 30, i32 2); 96*dc85d526SKyungwoo Lee ret i32 %1 97*dc85d526SKyungwoo Lee} 98*dc85d526SKyungwoo Leedefine i32 @f5() minsize { 99*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 20, i32 40, i32 2); 100*dc85d526SKyungwoo Lee ret i32 %1 101*dc85d526SKyungwoo Lee} 102*dc85d526SKyungwoo Leedefine i32 @f6() minsize { 103*dc85d526SKyungwoo Lee %1 = call i32 @g(i32 50, i32 60, i32 2); 104*dc85d526SKyungwoo Lee ret i32 %1 105*dc85d526SKyungwoo Lee} 106