[llvm] 470d59d - [DebugInfo][Reassociate] Fix missing debug location drop (#95355)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 16 18:06:24 PDT 2024
Author: Shan Huang
Date: 2024-06-17T09:06:20+08:00
New Revision: 470d59d6565f564701e1a1c194aeea4903d6baa1
URL: https://github.com/llvm/llvm-project/commit/470d59d6565f564701e1a1c194aeea4903d6baa1
DIFF: https://github.com/llvm/llvm-project/commit/470d59d6565f564701e1a1c194aeea4903d6baa1.diff
LOG: [DebugInfo][Reassociate] Fix missing debug location drop (#95355)
Fix #95343 .
Added:
llvm/test/Transforms/Reassociate/dropping_debugloc_the_neg.ll
Modified:
llvm/lib/Transforms/Scalar/Reassociate.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 5cfa5f46b3316..93d539efa16e7 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -844,7 +844,13 @@ static Value *NegateValue(Value *V, Instruction *BI,
->getIterator();
}
+ // Check that if TheNeg is moved out of its parent block, we drop its
+ // debug location to avoid extra coverage.
+ // See test dropping_debugloc_the_neg.ll for a detailed example.
+ if (TheNeg->getParent() != InsertPt->getParent())
+ TheNeg->dropLocation();
TheNeg->moveBefore(*InsertPt->getParent(), InsertPt);
+
if (TheNeg->getOpcode() == Instruction::Sub) {
TheNeg->setHasNoUnsignedWrap(false);
TheNeg->setHasNoSignedWrap(false);
diff --git a/llvm/test/Transforms/Reassociate/dropping_debugloc_the_neg.ll b/llvm/test/Transforms/Reassociate/dropping_debugloc_the_neg.ll
new file mode 100644
index 0000000000000..1c2fa9b664e08
--- /dev/null
+++ b/llvm/test/Transforms/Reassociate/dropping_debugloc_the_neg.ll
@@ -0,0 +1,54 @@
+; RUN: opt < %s -passes=reassociate -S | FileCheck %s
+
+; Check that Reassociate's NegateValue() drops the debug location of `%sub2`
+; when moving it out of the loop's body (`%for.body`) to `%for.cond`.
+
+define void @fn1(i32 %a, i1 %c, ptr %ptr) !dbg !5 {
+; CHECK-LABEL: define void @fn1(
+; CHECK: for.cond:
+; CHECK: [[SUB2:%.*]] = sub i32 0, %d.0{{$}}
+; CHECK: for.body:
+;
+entry:
+ br label %for.cond, !dbg !8
+
+for.cond: ; preds = %for.body, %entry
+ %d.0 = phi i32 [ 1, %entry ], [ 2, %for.body ], !dbg !9
+ br i1 %c, label %for.end, label %for.body, !dbg !10
+
+for.body: ; preds = %for.cond
+ %sub1 = sub i32 %a, %d.0, !dbg !11
+ %dead1 = add i32 %sub1, 1, !dbg !12
+ %dead2 = mul i32 %dead1, 3, !dbg !13
+ %dead3 = mul i32 %dead2, %sub1, !dbg !14
+ %sub2 = sub nsw i32 0, %d.0, !dbg !15
+ store i32 %sub2, ptr %ptr, align 4, !dbg !16
+ br label %for.cond, !dbg !17
+
+for.end: ; preds = %for.cond
+ ret void, !dbg !18
+}
+
+!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: "debugloc.ll", directory: "/")
+!2 = !{i32 11}
+!3 = !{i32 0}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "fn1", linkageName: "fn1", 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 = !DILocation(line: 11, column: 1, scope: !5)
More information about the llvm-commits
mailing list