Skip to content

Commit e7c9a6c

Browse files
committed
[SDAG] Don't move DBG_VALUE instructions after insertion point during scheduling (PR53243)
EmitSchedule() shouldn't be touching instructions after the provided insertion point. The change introduced in D83561 performs a scan to the end of the block, and thus may move unrelated instructions. In particular, this ends up moving instructions that have been produced by FastISel and will later be deleted. Moving them means that more instructions than intended are removed. Fix this by stopping the iteration when the insertion point is reached. Fixes llvm/llvm-project#53243. Differential Revision: https://reviews.llvm.org/D117489
1 parent 4f8fdf7 commit e7c9a6c

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,12 +1057,13 @@ EmitSchedule(MachineBasicBlock::iterator &InsertPos) {
10571057
"first terminator cannot be a debug value");
10581058
for (MachineInstr &MI : make_early_inc_range(
10591059
make_range(std::next(FirstTerm), InsertBB->end()))) {
1060+
// Only scan up to insertion point.
1061+
if (&MI == InsertPos)
1062+
break;
1063+
10601064
if (!MI.isDebugValue())
10611065
continue;
10621066

1063-
if (&MI == InsertPos)
1064-
InsertPos = std::prev(InsertPos->getIterator());
1065-
10661067
// The DBG_VALUE was referencing a value produced by a terminator. By
10671068
// moving the DBG_VALUE, the referenced value also needs invalidating.
10681069
MI.getOperand(0).ChangeToRegister(0, false);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -fast-isel -mtriple=x86_64-- < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: test:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: jmp set_state@PLT # TAILCALL
8+
tail call void @set_state()
9+
call void @llvm.dbg.value(metadata i64 0, metadata !10, metadata !DIExpression()), !dbg !16
10+
ret void
11+
}
12+
13+
declare void @set_state()
14+
15+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
16+
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
17+
18+
attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
19+
20+
!llvm.module.flags = !{!0}
21+
!llvm.dbg.cu = !{!1}
22+
23+
!0 = !{i32 2, !"Debug Info Version", i32 3}
24+
!1 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !2, producer: "clang LLVM (rustc version 1.60.0-nightly (ec4bcaac4 2022-01-15))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
25+
!2 = !DIFile(filename: "src/lib.rs/@/bug.63e521cd-cgu.0", directory: "/tmp/rust-bug")
26+
!3 = !{!4}
27+
!4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Option", file: !5, baseType: !6, size: 8, align: 8, flags: DIFlagEnumClass, elements: !7)
28+
!5 = !DIFile(filename: "<unknown>", directory: "")
29+
!6 = !DIBasicType(name: "u8", size: 8, encoding: DW_ATE_unsigned)
30+
!7 = !{!8, !9}
31+
!8 = !DIEnumerator(name: "None", value: 0)
32+
!9 = !DIEnumerator(name: "Some", value: 1)
33+
!10 = !DILocalVariable(name: "msg", arg: 2, scope: !11, file: !12, line: 689, type: !6)
34+
!11 = distinct !DISubprogram(name: "expect<()>", linkageName: "_ZN4core6option15Option$LT$T$GT$6expect17h9a574c18f194c213E", scope: !4, file: !12, line: 689, type: !13, scopeLine: 689, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !1, templateParams: !15, retainedNodes: !15)
35+
!12 = !DIFile(filename: "/rustc/ec4bcaac450279b029f3480b8b8f1b82ab36a5eb/library/core/src/option.rs", directory: "", checksumkind: CSK_MD5, checksum: "4120c8557937a0772190a676ec193800")
36+
!13 = !DISubroutineType(types: !14)
37+
!14 = !{null, !4}
38+
!15 = !{}
39+
!16 = !DILocation(line: 0, scope: !11)

0 commit comments

Comments
 (0)