[llvm] a6edaeb - [DebugInfo][TailCallElim] Use ret DILocation for return value selects (#134825)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 04:49:02 PDT 2025


Author: Stephen Tozer
Date: 2025-04-09T12:48:59+01:00
New Revision: a6edaeb824f138a364f4818c4261eb27153a12ac

URL: https://github.com/llvm/llvm-project/commit/a6edaeb824f138a364f4818c4261eb27153a12ac
DIFF: https://github.com/llvm/llvm-project/commit/a6edaeb824f138a364f4818c4261eb27153a12ac.diff

LOG: [DebugInfo][TailCallElim] Use ret DILocation for return value selects (#134825)

In TailRecursionElimination we may insert a select before the return to
choose the return value if necessary; this select is effectively part of
the return statement, and so should use its DILocation.

Found using https://github.com/llvm/llvm-project/pull/107279.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
    llvm/test/Transforms/TailCallElim/debugloc.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
index 3f27166080d5a..7dd6c60370ed9 100644
--- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -725,6 +725,7 @@ bool TailRecursionEliminator::eliminateCall(CallInst *CI) {
       SelectInst *SI =
           SelectInst::Create(RetKnownPN, RetPN, Ret->getReturnValue(),
                              "current.ret.tr", Ret->getIterator());
+      SI->setDebugLoc(Ret->getDebugLoc());
       RetSelects.push_back(SI);
 
       RetPN->addIncoming(SI, BB);

diff  --git a/llvm/test/Transforms/TailCallElim/debugloc.ll b/llvm/test/Transforms/TailCallElim/debugloc.ll
index 1670b832e9d97..7a3a8f90cb6af 100644
--- a/llvm/test/Transforms/TailCallElim/debugloc.ll
+++ b/llvm/test/Transforms/TailCallElim/debugloc.ll
@@ -1,16 +1,18 @@
 ; RUN: opt < %s -passes=debugify,tailcallelim -S | FileCheck %s
 
-define void @foo() {
+define i32 @foo() {
 entry:
 ; CHECK-LABEL: entry:
 ; CHECK: br label %tailrecurse{{$}}
 
-  call void @foo()                            ;; line 1
-  ret void
+  %ret = call i32 @foo()                          ;; line 1
+  ret i32 0                                       ;; line 2
 
 ; CHECK-LABEL: tailrecurse:
-; CHECK: br label %tailrecurse, !dbg ![[DbgLoc:[0-9]+]]
+; CHECK: select i1 {{.+}}, !dbg ![[DbgLoc2:[0-9]+]]
+; CHECK: br label %tailrecurse, !dbg ![[DbgLoc1:[0-9]+]]
 }
 
 ;; Make sure tailrecurse has the call instruction's DL
-; CHECK: ![[DbgLoc]] = !DILocation(line: 1
+; CHECK: ![[DbgLoc1]] = !DILocation(line: 1
+; CHECK: ![[DbgLoc2]] = !DILocation(line: 2


        


More information about the llvm-commits mailing list