[PATCH] D60419: Avoid removing physreg uses in MachineDCE with LIS present
Stanislav Mekhanoshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 12:18:19 PDT 2019
rampitec created this revision.
rampitec added a reviewer: bjope.
One of OOT targets hits "Live segment doesn't end at a valid instruction"
error if physreg use is removed. I do not have a reproducer for that or
access to the target, but that seems to be reasonable to avoid removing
dead phys reg uses for the same reason as dead defs.
https://reviews.llvm.org/D60419
Files:
lib/CodeGen/DeadMachineInstructionElim.cpp
Index: lib/CodeGen/DeadMachineInstructionElim.cpp
===================================================================
--- lib/CodeGen/DeadMachineInstructionElim.cpp
+++ lib/CodeGen/DeadMachineInstructionElim.cpp
@@ -77,24 +77,32 @@
// Examine each operand.
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
- if (MO.isReg() && MO.isDef()) {
- unsigned Reg = MO.getReg();
- if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
- // Don't delete live physreg defs, or any reserved register defs.
- // Do not remove physreg defs if we have LIS as we may be unable
- // to accurately recompute its liveness.
- if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg) || LIS)
+ if (!MO.isReg())
+ continue;
+
+ unsigned Reg = MO.getReg();
+ // Do not remove physreg defs or uses if we have LIS as we may be unable
+ // to accurately recompute its liveness.
+ if (LIS && TargetRegisterInfo::isPhysicalRegister(Reg) &&
+ MRI->isAllocatable(Reg))
+ return false;
+
+ if (!MO.isDef())
+ continue;
+
+ if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
+ // Don't delete live physreg defs, or any reserved register defs.
+ if (LivePhysRegs.test(Reg) || MRI->isReserved(Reg) || LIS)
+ return false;
+ } else {
+ // An instruction can also use its def in case if it is a tied operand.
+ // TODO: Technically we can also remove it if def dominates the use.
+ // This can happen when two instructions define different subregs
+ // of the same register.
+ for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) {
+ if (&Use != MI)
+ // This def has a non-debug use. Don't delete the instruction!
return false;
- } else {
- // An instruction can also use its def in case if it is a tied operand.
- // TODO: Technically we can also remove it if def dominates the use.
- // This can happen when two instructions define different subregs
- // of the same register.
- for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) {
- if (&Use != MI)
- // This def has a non-debug use. Don't delete the instruction!
- return false;
- }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60419.194192.patch
Type: text/x-patch
Size: 2368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190408/b4f0753c/attachment.bin>
More information about the llvm-commits
mailing list