Skip to content

[DebugInfo][TailCallElim] Use ret DILocation for return value selects #134825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

SLTozer
Copy link
Contributor

@SLTozer SLTozer commented Apr 8, 2025

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 #107279.

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.
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-debuginfo

Author: Stephen Tozer (SLTozer)

Changes

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 #107279.


Full diff: https://github.com/llvm/llvm-project/pull/134825.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp (+1)
  • (modified) llvm/test/Transforms/TailCallElim/debugloc.ll (+7-5)
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

Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding these, seems like your technique is working well! 😄

Copy link
Contributor

@Apochens Apochens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you have found a lot of cases where the missing debug locations are caused by newly created instructions that are not assigned any location. That's great!

@SLTozer SLTozer merged commit a6edaeb into llvm:main Apr 9, 2025
14 checks passed
AllinLeeYL pushed a commit to AllinLeeYL/llvm-project that referenced this pull request Apr 10, 2025
…llvm#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 llvm#107279.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…llvm#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 llvm#107279.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants