Skip to content

Commit 5dab1fa

Browse files
committed
[BranchFolding] Follow up #149999 crash fix
fbf6271 introduced an assertion failure as setDebugValueUndef was called on DBG_LABELs, which isn't allowed and doesn't make sense. Fix by skipping the call for DBG_LABELs and hoisting, in line with the original behaviour.
1 parent 0d21522 commit 5dab1fa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,8 +2103,9 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
21032103
DI->eraseFromParent();
21042104
return;
21052105
}
2106-
2107-
DI->setDebugValueUndef();
2106+
// Move DBG_LABELs without modifying them. Set DBG_VALUEs undef.
2107+
if (!DI->isDebugLabel())
2108+
DI->setDebugValueUndef();
21082109
DI->moveBefore(&*Loc);
21092110
};
21102111

llvm/test/DebugInfo/X86/branch-folder-dbg.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
## can be killed.
1010
##
1111
## Check DBG_PHIs are deleted rather than hoisted (implicit-check-not).
12+
##
13+
## Check DBG_LABELs are hoisted and not modified (and don't cause a crash).
1214

1315
# CHECK: bb.0
1416
# CHECK: CALL64pcrel32 @f, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
1517
## --- Start splice from bb.2.if.else (and debug instructions from bb.1.if.then) ---
18+
# CHECK-NEXT: DBG_LABEL 0
1619
# CHECK-NEXT: DBG_VALUE $noreg, $noreg, ![[#]], !DIExpression(), debug-___location ![[#]]
20+
# CHECK-NEXT: DBG_LABEL 1
1721
# CHECK-NEXT: DBG_VALUE $noreg, $noreg, ![[#]], !DIExpression(), debug-___location ![[#]]
1822
# CHECK-NEXT: $edi = MOV32r0 implicit-def dead $eflags, debug-instr-number 2, debug-___location !DILocation(line: 0, scope: ![[#]])
1923
# CHECK-NEXT: DBG_VALUE $noreg, $noreg, ![[#]], !DIExpression(DW_OP_LLVM_arg, 0), debug-___location ![[#]]
@@ -98,6 +102,7 @@ body: |
98102
successors: %bb.3(0x80000000)
99103
100104
DBG_PHI $esp, 3
105+
DBG_LABEL 0
101106
DBG_VALUE $esi, $noreg, !11, !DIExpression(), debug-___location !13
102107
$edi = MOV32r0 implicit-def dead $eflags, debug-instr-number 1, debug-___location !14
103108
DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-___location !13
@@ -109,6 +114,7 @@ body: |
109114
successors: %bb.3(0x80000000)
110115
111116
DBG_PHI $esp, 4
117+
DBG_LABEL 1
112118
DBG_VALUE $esp, $noreg, !11, !DIExpression(), debug-___location !13
113119
$edi = MOV32r0 implicit-def dead $eflags, debug-instr-number 2, debug-___location !16
114120
DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-___location !13

0 commit comments

Comments
 (0)