[PATCH] D145759: [MachineCombiner] Preserve debug instruction number
Felipe de Azevedo Piovezan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 19:39:46 PST 2023
fdeazeve updated this revision to Diff 504012.
fdeazeve added a comment.
Remove WIP comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145759/new/
https://reviews.llvm.org/D145759
Files:
llvm/lib/CodeGen/TargetInstrInfo.cpp
llvm/test/CodeGen/X86/machine-combiner-dbg.ll
Index: llvm/test/CodeGen/X86/machine-combiner-dbg.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/machine-combiner-dbg.ll
@@ -0,0 +1,37 @@
+; RUN: llc -mtriple=x86_64-gnu-linux -stop-after=machine-combiner < %s | FileCheck %s
+
+define float @reassoc_me(float %f1, float %f2, float %f3, float %f4) !dbg !9 {
+ %add = fadd reassoc nsz float %f1, %f2, !dbg !21
+ %add1 = fadd reassoc nsz float %add, %f3, !dbg !21
+ %add2 = fadd reassoc nsz float %add1, %f4, !dbg !21
+ call void @llvm.dbg.value(metadata float %add2, metadata !20, metadata !DIExpression()), !dbg !21
+ ret float %add2, !dbg !21
+}
+
+; CHECK: ![[VAR:.*]] = !DILocalVariable(name: "temp3"
+
+; CHECK: %[[arg3:.*]]:fr32 = COPY $xmm3
+; CHECK-NEXT: %[[arg2:.*]]:fr32 = COPY $xmm2
+; CHECK-NEXT: %[[arg1:.*]]:fr32 = COPY $xmm1
+; CHECK-NEXT: %[[arg0:.*]]:fr32 = COPY $xmm0
+; CHECK-NEXT: %[[add1:.*]]:fr32 = {{.*}} ADDSSrr %[[arg0]], %[[arg1]]
+; CHECK-NEXT: %[[add2:.*]]:fr32 = {{.*}} ADDSSrr %[[arg2]], %[[arg3]]
+; CHECK-NEXT: ADDSSrr %[[add1]], killed %[[add2]], {{.*}} debug-instr-number 1
+; CHECK-NEXT: DBG_INSTR_REF ![[VAR]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0)
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "hello", isOptimized: true, emissionKind: FullDebug)
+!1 = !DIFile(filename: "reassoc.c", directory: "blah")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = distinct !DISubprogram(name: "reassoc_me", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
+!10 = !DISubroutineType(types: !11)
+!11 = !{!12, !12, !12, !12, !12}
+!12 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!13 = !{!20}
+!20 = !DILocalVariable(name: "temp3", scope: !9, file: !1, line: 4, type: !12)
+!21 = !DILocation(line: 0, scope: !9)
Index: llvm/lib/CodeGen/TargetInstrInfo.cpp
===================================================================
--- llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -1017,6 +1017,17 @@
InsInstrs.push_back(MIB2);
DelInstrs.push_back(&Prev);
DelInstrs.push_back(&Root);
+
+ // We transformed:
+ // B = A op X (Prev)
+ // C = B op Y (Root)
+ // Into:
+ // B = X op Y (MIB1)
+ // C = A op B (MIB2)
+ // C has the same value as before, B doesn't; as such, keep the debug number
+ // of C but not of B.
+ if (unsigned OldRootNum = Root.peekDebugInstrNum())
+ MIB2.getInstr()->setDebugInstrNum(OldRootNum);
}
void TargetInstrInfo::genAlternativeCodeSequence(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145759.504012.patch
Type: text/x-patch
Size: 2853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230310/66e5677d/attachment.bin>
More information about the llvm-commits
mailing list