llvm.org GIT mirror llvm / ebe6584
TRE: make TRE a bit more aggressive Make tail recursion elimination a bit more aggressive. This allows us to get tail recursion on functions that are just branches to a different function. The fact that the function takes a byval argument does not restrict it from being optimised into just a tail call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219899 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 4 years ago
4 changed file(s) with 39 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
248248 return false;
249249 AllCallsAreTailCalls = true;
250250
251 // The local stack holds all alloca instructions and all byval arguments.
252251 AllocaDerivedValueTracker Tracker;
253 for (Argument &Arg : F.args()) {
254 if (Arg.hasByValAttr())
255 Tracker.walk(&Arg);
256 }
257252 for (auto &BB : F) {
258253 for (auto &I : BB)
259254 if (AllocaInst *AI = dyn_cast(&I))
309304 for (auto &Arg : CI->arg_operands()) {
310305 if (isa(Arg.getUser()))
311306 continue;
312 if (Argument *A = dyn_cast(Arg.getUser()))
313 if (!A->hasByValAttr())
314 continue;
307 if (isa(Arg.getUser()))
308 continue;
315309 SafeToTail = false;
316310 break;
317311 }
2626 tail call void @ext(i32* null)
2727 ret void
2828 }
29
2930 define void @frob(i32* %x) {
3031 ; CHECK-LABEL: define void @frob(
3132 ; CHECK: alloca i32
32 ; CHECK: {{^ *}}call void @ext(
33 ; CHECK: {{^ *}}tail call void @ext(
3334 ; CHECK: tail call void @ext(i32* null)
3435 ; CHECK: ret void
3536 tail call void @qux(i32* byval %x)
146146 ; Don't tail call if a byval arg is captured.
147147 define void @test9(i32* byval %a) {
148148 ; CHECK-LABEL: define void @test9(
149 ; CHECK: {{^ *}}call void @use(
149 ; CHECK: {{^ *}}tail call void @use(
150150 call void @use(i32* %a)
151151 ret void
152152 }
0 ; RUN: opt -mtriple i386 -Os -S %s -o - | FileCheck %s
1 ; RUN: opt -mtriple x86_64 -Os -S %s -o - | FileCheck %s
2 ; RUN: opt -mtriple armv7 -Os -S %s -o - | FileCheck %s
3
4 %struct.D16 = type { [16 x double] }
5
6 declare void @_Z2OpP3D16PKS_S2_(%struct.D16*, %struct.D16*, %struct.D16*)
7
8 define void @_Z7TestRefRK3D16S1_(%struct.D16* noalias sret %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) {
9 %1 = alloca %struct.D16*, align 8
10 %2 = alloca %struct.D16*, align 8
11 store %struct.D16* %RHS, %struct.D16** %1, align 8
12 store %struct.D16* %LHS, %struct.D16** %2, align 8
13 %3 = load %struct.D16** %1, align 8
14 %4 = load %struct.D16** %2, align 8
15 call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %3, %struct.D16* %4)
16 ret void
17 }
18
19 ; CHECK: define void @_Z7TestRefRK3D16S1_({{.*}}) {
20 ; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
21 ; CHECK: ret void
22 ; CHECK: }
23
24 define void @_Z7TestVal3D16S_(%struct.D16* noalias sret %agg.result, %struct.D16* byval align 8 %RHS, %struct.D16* byval align 8 %LHS) {
25 call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
26 ret void
27 }
28
29 ; CHECK: define void @_Z7TestVal3D16S_({{.*}}) {
30 ; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
31 ; CHECK: ret void
32 ; CHECK: }
33