From 7da1ea83a9fd020b73a7c368b64fe231fb789966 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 17 Oct 2014 21:25:48 +0000 Subject: [PATCH] Revert "TRE: make TRE a bit more aggressive" This reverts commit r219899. This also updates byval-tail-call.ll to make it clear what was breaking. Adding r219899 again will cause the load/store to disappear. llvm-svn: 220093 --- .../Transforms/Scalar/TailRecursionElimination.cpp | 10 +++++-- llvm/test/Transforms/Inline/byval-tail-call.ll | 8 +++-- llvm/test/Transforms/TailCallElim/basic.ll | 2 +- llvm/test/Transforms/TailCallElim/byval.ll | 34 ---------------------- 4 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 llvm/test/Transforms/TailCallElim/byval.ll diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp index f8eafc8..b758025 100644 --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -249,7 +249,12 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) { return false; AllCallsAreTailCalls = true; + // The local stack holds all alloca instructions and all byval arguments. AllocaDerivedValueTracker Tracker; + for (Argument &Arg : F.args()) { + if (Arg.hasByValAttr()) + Tracker.walk(&Arg); + } for (auto &BB : F) { for (auto &I : BB) if (AllocaInst *AI = dyn_cast(&I)) @@ -305,8 +310,9 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) { for (auto &Arg : CI->arg_operands()) { if (isa(Arg.getUser())) continue; - if (isa(Arg.getUser())) - continue; + if (Argument *A = dyn_cast(Arg.getUser())) + if (!A->hasByValAttr()) + continue; SafeToTail = false; break; } diff --git a/llvm/test/Transforms/Inline/byval-tail-call.ll b/llvm/test/Transforms/Inline/byval-tail-call.ll index e80bae1..154f397 100644 --- a/llvm/test/Transforms/Inline/byval-tail-call.ll +++ b/llvm/test/Transforms/Inline/byval-tail-call.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -tailcallelim -inline -instcombine -dse -S | FileCheck %s +; RUN: opt < %s -basicaa -tailcallelim -inline -instcombine -dse -S | FileCheck %s ; PR7272 ; Calls that capture byval parameters cannot be marked as tail calls. Other @@ -30,8 +30,10 @@ define internal void @qux(i32* byval %x) { define void @frob(i32* %x) { ; CHECK-LABEL: define void @frob( -; CHECK: alloca i32 -; CHECK: {{^ *}}tail call void @ext( +; CHECK: %[[POS:.*]] = alloca i32 +; CHECK: %[[VAL:.*]] = load i32* %x +; CHECK: store i32 %[[VAL]], i32* %[[POS]] +; CHECK: {{^ *}}call void @ext(i32* %[[POS]] ; CHECK: tail call void @ext(i32* null) ; CHECK: ret void tail call void @qux(i32* byval %x) diff --git a/llvm/test/Transforms/TailCallElim/basic.ll b/llvm/test/Transforms/TailCallElim/basic.ll index c7af9af..8e9814b 100644 --- a/llvm/test/Transforms/TailCallElim/basic.ll +++ b/llvm/test/Transforms/TailCallElim/basic.ll @@ -147,7 +147,7 @@ cond_false: ; Don't tail call if a byval arg is captured. define void @test9(i32* byval %a) { ; CHECK-LABEL: define void @test9( -; CHECK: {{^ *}}tail call void @use( +; CHECK: {{^ *}}call void @use( call void @use(i32* %a) ret void } diff --git a/llvm/test/Transforms/TailCallElim/byval.ll b/llvm/test/Transforms/TailCallElim/byval.ll deleted file mode 100644 index 1150f76..0000000 --- a/llvm/test/Transforms/TailCallElim/byval.ll +++ /dev/null @@ -1,34 +0,0 @@ -; RUN: opt -mtriple i386 -Os -S %s -o - | FileCheck %s -; RUN: opt -mtriple x86_64 -Os -S %s -o - | FileCheck %s -; RUN: opt -mtriple armv7 -Os -S %s -o - | FileCheck %s - -%struct.D16 = type { [16 x double] } - -declare void @_Z2OpP3D16PKS_S2_(%struct.D16*, %struct.D16*, %struct.D16*) - -define void @_Z7TestRefRK3D16S1_(%struct.D16* noalias sret %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) { - %1 = alloca %struct.D16*, align 8 - %2 = alloca %struct.D16*, align 8 - store %struct.D16* %RHS, %struct.D16** %1, align 8 - store %struct.D16* %LHS, %struct.D16** %2, align 8 - %3 = load %struct.D16** %1, align 8 - %4 = load %struct.D16** %2, align 8 - call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %3, %struct.D16* %4) - ret void -} - -; CHECK: define void @_Z7TestRefRK3D16S1_({{.*}}) { -; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) -; CHECK: ret void -; CHECK: } - -define void @_Z7TestVal3D16S_(%struct.D16* noalias sret %agg.result, %struct.D16* byval align 8 %RHS, %struct.D16* byval align 8 %LHS) { - call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) - ret void -} - -; CHECK: define void @_Z7TestVal3D16S_({{.*}}) { -; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) -; CHECK: ret void -; CHECK: } - -- 2.7.4