[MachineCSE] Don't carry the wrong location when hoisting
PR: 45425
<rdar://problem/61359768>
Differential Revision: https://reviews.llvm.org/D77604
diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp
index 9561a06..8c195ad 100644
--- a/llvm/lib/CodeGen/MachineCSE.cpp
+++ b/llvm/lib/CodeGen/MachineCSE.cpp
@@ -831,6 +831,13 @@
continue;
MachineInstr &NewMI =
TII->duplicate(*CMBB, CMBB->getFirstTerminator(), *MI);
+
+ // When hoisting, make sure we don't carry the debug location of
+ // the original instruction, as that's not correct and can cause
+ // unexpected jumps when debugging optimized code.
+ auto EmptyDL = DebugLoc();
+ NewMI.setDebugLoc(EmptyDL);
+
NewMI.getOperand(0).setReg(NewReg);
PREMap[MI] = CMBB;