From 4dfe279e00d56f23c37a526b3abe0a7c89269fa7 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Fri, 3 Aug 2018 20:27:13 +0000 Subject: [PATCH] [TRE][DebugInfo] Preserve Debug Location in new branch instruction There are two branch instructions created so the new test covers them both. Differential Revision: https://reviews.llvm.org/D50263 llvm-svn: 338917 --- .../Scalar/TailRecursionElimination.cpp | 3 ++- llvm/test/Transforms/TailCallElim/debugloc.ll | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/TailCallElim/debugloc.ll diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp index f8cd6c17a5a6..818e8373b1c9 100644 --- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -566,7 +566,8 @@ static bool eliminateRecursiveTailCall(CallInst *CI, ReturnInst *Ret, BasicBlock *NewEntry = BasicBlock::Create(F->getContext(), "", F, OldEntry); NewEntry->takeName(OldEntry); OldEntry->setName("tailrecurse"); - BranchInst::Create(OldEntry, NewEntry); + BranchInst *BI = BranchInst::Create(OldEntry, NewEntry); + BI->setDebugLoc(CI->getDebugLoc()); // If this tail call is marked 'tail' and if there are any allocas in the // entry block, move them up to the new entry block. diff --git a/llvm/test/Transforms/TailCallElim/debugloc.ll b/llvm/test/Transforms/TailCallElim/debugloc.ll new file mode 100644 index 000000000000..412dd04b621a --- /dev/null +++ b/llvm/test/Transforms/TailCallElim/debugloc.ll @@ -0,0 +1,16 @@ +; RUN: opt < %s -debugify -tailcallelim -S | FileCheck %s + +define void @foo() { +entry: +; CHECK-LABEL: entry: +; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]] + + call void @foo() ;; line 1 + ret void + +; CHECK-LABEL: tailrecurse: +; CHECK: br label %tailrecurse, !dbg ![[DbgLoc]] +} + +;; Make sure tailrecurse has the call instruction's DL +; CHECK: ![[DbgLoc]] = !DILocation(line: 1