-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo][TailCallElim] Drop the debug location of AccRecInstrNew #95742
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
Apochens
merged 1 commit into
llvm:main
from
Apochens:#95731_tailcallelim_accrecinstrnew_drop_location
Jun 20, 2024
Merged
[DebugInfo][TailCallElim] Drop the debug location of AccRecInstrNew #95742
Apochens
merged 1 commit into
llvm:main
from
Apochens:#95731_tailcallelim_accrecinstrnew_drop_location
Jun 20, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-llvm-transforms Author: Shan Huang (Apochens) ChangesFix #95731 . Full diff: https://github.com/llvm/llvm-project/pull/95742.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
index bc4b6de2f07f1..f413e4e1c15ac 100644
--- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -779,6 +779,7 @@ void TailRecursionEliminator::cleanupAndFinalize() {
AccRecInstrNew->setOperand(AccRecInstr->getOperand(0) == AccPN,
RI->getOperand(0));
AccRecInstrNew->insertBefore(RI);
+ AccRecInstrNew->dropLocation();
RI->setOperand(0, AccRecInstrNew);
}
}
@@ -807,6 +808,7 @@ void TailRecursionEliminator::cleanupAndFinalize() {
AccRecInstrNew->setOperand(AccRecInstr->getOperand(0) == AccPN,
SI->getFalseValue());
AccRecInstrNew->insertBefore(SI);
+ AccRecInstrNew->dropLocation();
SI->setFalseValue(AccRecInstrNew);
}
}
diff --git a/llvm/test/Transforms/TailCallElim/dropping_debugloc_acc_rec_inst_rnew.ll b/llvm/test/Transforms/TailCallElim/dropping_debugloc_acc_rec_inst_rnew.ll
new file mode 100644
index 0000000000000..4028a472daba9
--- /dev/null
+++ b/llvm/test/Transforms/TailCallElim/dropping_debugloc_acc_rec_inst_rnew.ll
@@ -0,0 +1,109 @@
+; RUN: opt -S -passes=tailcallelim < %s | FileCheck %s
+
+; Check that TailCallElim's cleanupAndFinalize drops the debug location of `AccRecInstrNew`,
+; because it is cloned from `AccRecInstr` (`%accumulate*` in the following IR) with the
+; debug location and inserted into the block of a different branch.
+; @test6_multiple_returns tests that when RetSelects.empty() is false (no select instruction is inserted)
+; @test7_multiple_accumulators tests it when RetSelects.empty() is true
+
+define i32 @test6_multiple_returns(i32 %x, i32 %y) local_unnamed_addr !dbg !5 {
+; CHECK-LABEL: define i32 @test6_multiple_returns(
+; CHECK: case0:
+; CHECK: [[ACCUMULATOR_RET_TR2:%.*]] = add i32 %accumulator.tr, %helper{{$}}
+; CHECK: case99:
+; CHECK: [[ACCUMULATOR_RET_TR:%.*]] = add i32 %accumulator.tr, 18{{$}}
+; CHECK: default:
+;
+entry:
+ switch i32 %x, label %default [
+ i32 0, label %case0
+ i32 99, label %case99
+ ], !dbg !8
+
+case0: ; preds = %entry
+ %helper = call i32 @test6_helper(), !dbg !9
+ ret i32 %helper, !dbg !10
+
+case99: ; preds = %entry
+ %sub1 = add i32 %x, -1, !dbg !11
+ %recurse1 = call i32 @test6_multiple_returns(i32 %sub1, i32 %y), !dbg !12
+ ret i32 18, !dbg !13
+
+default: ; preds = %entry
+ %sub2 = add i32 %x, -1, !dbg !14
+ %recurse2 = call i32 @test6_multiple_returns(i32 %sub2, i32 %y), !dbg !15
+ %accumulate = add i32 %recurse2, %y, !dbg !16
+ ret i32 %accumulate, !dbg !17
+}
+
+declare i32 @test6_helper()
+
+define i32 @test7_multiple_accumulators(i32 %a) local_unnamed_addr !dbg !18 {
+; CHECK-LABEL: define i32 @test7_multiple_accumulators(
+; CHECK: if.end3:
+; CHECK: [[ACCUMULATOR_RET_TR:%.*]] = add nsw i32 %accumulator.tr, [[ACCUMULATE2:.*]]{{$}}
+; CHECK: return:
+; CHECK: [[ACCUMULATOR_RET_TR1:%.*]] = add nsw i32 %accumulator.tr, 0{{$}}
+;
+entry:
+ %tobool = icmp eq i32 %a, 0, !dbg !19
+ br i1 %tobool, label %return, label %if.end, !dbg !20
+
+if.end: ; preds = %entry
+ %and = and i32 %a, 1, !dbg !21
+ %tobool1 = icmp eq i32 %and, 0, !dbg !22
+ %sub = add nsw i32 %a, -1, !dbg !23
+ br i1 %tobool1, label %if.end3, label %if.then2, !dbg !24
+
+if.then2: ; preds = %if.end
+ %recurse1 = tail call i32 @test7_multiple_accumulators(i32 %sub), !dbg !25
+ %accumulate1 = add nsw i32 %recurse1, 1, !dbg !26
+ br label %return, !dbg !27
+
+if.end3: ; preds = %if.end
+ %recurse2 = tail call i32 @test7_multiple_accumulators(i32 %sub), !dbg !28
+ %accumulate2 = mul nsw i32 %recurse2, 2, !dbg !29
+ br label %return, !dbg !30
+
+return: ; preds = %if.end3, %if.then2, %entry
+ %retval.0 = phi i32 [ %accumulate1, %if.then2 ], [ %accumulate2, %if.end3 ], [ 0, %entry ], !dbg !31
+ ret i32 %retval.0, !dbg !32
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!2, !3}
+!llvm.module.flags = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "all.ll", directory: "/")
+!2 = !{i32 24}
+!3 = !{i32 0}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "test6_multiple_returns", linkageName: "test6_multiple_returns", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !DILocation(line: 1, column: 1, scope: !5)
+!9 = !DILocation(line: 2, column: 1, scope: !5)
+!10 = !DILocation(line: 3, column: 1, scope: !5)
+!11 = !DILocation(line: 4, column: 1, scope: !5)
+!12 = !DILocation(line: 5, column: 1, scope: !5)
+!13 = !DILocation(line: 6, column: 1, scope: !5)
+!14 = !DILocation(line: 7, column: 1, scope: !5)
+!15 = !DILocation(line: 8, column: 1, scope: !5)
+!16 = !DILocation(line: 9, column: 1, scope: !5)
+!17 = !DILocation(line: 10, column: 1, scope: !5)
+!18 = distinct !DISubprogram(name: "test7_multiple_accumulators", linkageName: "test7_multiple_accumulators", scope: null, file: !1, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!19 = !DILocation(line: 11, column: 1, scope: !18)
+!20 = !DILocation(line: 12, column: 1, scope: !18)
+!21 = !DILocation(line: 13, column: 1, scope: !18)
+!22 = !DILocation(line: 14, column: 1, scope: !18)
+!23 = !DILocation(line: 15, column: 1, scope: !18)
+!24 = !DILocation(line: 16, column: 1, scope: !18)
+!25 = !DILocation(line: 17, column: 1, scope: !18)
+!26 = !DILocation(line: 18, column: 1, scope: !18)
+!27 = !DILocation(line: 19, column: 1, scope: !18)
+!28 = !DILocation(line: 20, column: 1, scope: !18)
+!29 = !DILocation(line: 21, column: 1, scope: !18)
+!30 = !DILocation(line: 22, column: 1, scope: !18)
+!31 = !DILocation(line: 23, column: 1, scope: !18)
+!32 = !DILocation(line: 24, column: 1, scope: !18)
|
OCHyams
approved these changes
Jun 17, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - looks like this patch prevents misleading bonus coverage
Thanks!
AlexisPerry
pushed a commit
to llvm-project-tlp/llvm-project
that referenced
this pull request
Jul 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #95731 .