-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo][IndVarSimplify] Fix missing debug location updates #91443
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
Conversation
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-llvm-transforms Author: Shan Huang (Apochens) Changesfix #91436 . Adding debug location updates for the newly created Full diff: https://github.com/llvm/llvm-project/pull/91443.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index ba392e187b8be..ff24c94aad2df 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -359,15 +359,18 @@ bool IndVarSimplify::handleFloatingPointIV(Loop *L, PHINode *PN) {
PHINode::Create(Int32Ty, 2, PN->getName() + ".int", PN->getIterator());
NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
PN->getIncomingBlock(IncomingEdge));
+ NewPHI->setDebugLoc(PN->getDebugLoc());
- Value *NewAdd =
+ Instruction *NewAdd =
BinaryOperator::CreateAdd(NewPHI, ConstantInt::get(Int32Ty, IncValue),
Incr->getName() + ".int", Incr->getIterator());
+ NewAdd->setDebugLoc(Incr->getDebugLoc());
NewPHI->addIncoming(NewAdd, PN->getIncomingBlock(BackEdge));
ICmpInst *NewCompare =
new ICmpInst(TheBr->getIterator(), NewPred, NewAdd,
ConstantInt::get(Int32Ty, ExitValue), Compare->getName());
+ NewCompare->setDebugLoc(Compare->getDebugLoc());
// In the following deletions, PN may become dead and may be deleted.
// Use a WeakTrackingVH to observe whether this happens.
@@ -391,8 +394,9 @@ bool IndVarSimplify::handleFloatingPointIV(Loop *L, PHINode *PN) {
// We give preference to sitofp over uitofp because it is faster on most
// platforms.
if (WeakPH) {
- Value *Conv = new SIToFPInst(NewPHI, PN->getType(), "indvar.conv",
+ Instruction *Conv = new SIToFPInst(NewPHI, PN->getType(), "indvar.conv",
PN->getParent()->getFirstInsertionPt());
+ Conv->setDebugLoc(PN->getDebugLoc());
PN->replaceAllUsesWith(Conv);
RecursivelyDeleteTriviallyDeadInstructions(PN, TLI, MSSAU.get());
}
diff --git a/llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll b/llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll
new file mode 100644
index 0000000000000..c9af3546c9612
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll
@@ -0,0 +1,65 @@
+; RUN: opt < %s -passes=indvars -S | FileCheck %s
+
+; This testcase checks the preservation of debug locations of newly created
+; phi, sitofp, add and icmp instructions in IndVarSimplify Pass.
+
+define void @test1() !dbg !5 {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[BB:%.*]], !dbg
+; CHECK: bb:
+; CHECK: [[IV_INT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[DOTINT:%.*]], [[BB]] ], !dbg
+; CHECK: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to double, !dbg
+; CHECK: [[DOTINT]] = add nuw nsw i32 [[IV_INT]], 1, !dbg
+; CHECK: [[TMP1:%.*]] = icmp ult i32 [[DOTINT]], 10000, !dbg
+;
+entry:
+ br label %bb, !dbg !16
+
+bb: ; preds = %bb, %entry
+ %iv = phi double [ 0.000000e+00, %entry ], [ %1, %bb ], !dbg !17
+ tail call void @llvm.dbg.value(metadata double %iv, metadata !9, metadata !DIExpression()), !dbg !17
+ %0 = tail call i32 @foo(double %iv), !dbg !18
+ tail call void @llvm.dbg.value(metadata i32 %0, metadata !11, metadata !DIExpression()), !dbg !18
+ %1 = fadd double %iv, 1.000000e+00, !dbg !19
+ tail call void @llvm.dbg.value(metadata double %1, metadata !13, metadata !DIExpression()), !dbg !19
+ %2 = fcmp olt double %1, 1.000000e+04, !dbg !20
+ tail call void @llvm.dbg.value(metadata i1 %2, metadata !14, metadata !DIExpression()), !dbg !20
+ br i1 %2, label %bb, label %return, !dbg !21
+
+return: ; preds = %bb
+ ret void, !dbg !22
+}
+
+declare i32 @foo(double)
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!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: "indvars-preserving.ll", directory: "/")
+!2 = !{i32 7}
+!3 = !{i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{}
+!8 = !{!9, !11, !13, !14}
+!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 2, type: !10)
+!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
+!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 3, type: !12)
+!12 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+!13 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 4, type: !10)
+!14 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 5, type: !15)
+!15 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned)
+!16 = !DILocation(line: 1, column: 1, scope: !5)
+!17 = !DILocation(line: 2, column: 1, scope: !5)
+!18 = !DILocation(line: 3, column: 1, scope: !5)
+!19 = !DILocation(line: 4, column: 1, scope: !5)
+!20 = !DILocation(line: 5, column: 1, scope: !5)
+!21 = !DILocation(line: 6, column: 1, scope: !5)
+!22 = !DILocation(line: 7, column: 1, scope: !5)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
@SLTozer Sorry for this direct ping. Could you please help me check this PR and assign reviewers? |
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.
Other than a few comments for the test this LGTM, thanks for the patch
llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll
Outdated
Show resolved
Hide resolved
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.
Thanks for working on this! 😄
Change looks correct to me overall. The pass is creating replacement instructions, so it makes sense to copy over the original location as you have done here.
Just a small nit in the test to fix up.
llvm/test/Transforms/IndVarSimplify/indvars-preversing-debugloc.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/IndVarSimplify/indvars-preserving-debugloc.ll
Outdated
Show resolved
Hide resolved
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.
Thanks for working on this! It now looks ready to go to me. 😄
Since you don't have merge access, I'll plan to merge this after waiting a day for others to review if they wish to.
fix #91436 . Adding debug location updates for the newly created
phi
,add
,icmp
andsitofp
instructions, respectively.