From 0e43f63ac7fa5e28497760a0dfec2fe20557bce0 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Wed, 12 Aug 2026 01:22:08 +0800 Subject: [CodeGen] Track reserved register defs precisely --- backend/lib/CodeGen/MachineLiveness.cpp | 15 +++++++-------- backend/lib/CodeGen/PostRAScheduler.cpp | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'backend/lib') diff --git a/backend/lib/CodeGen/MachineLiveness.cpp b/backend/lib/CodeGen/MachineLiveness.cpp index 528a675..7984e7d 100644 --- a/backend/lib/CodeGen/MachineLiveness.cpp +++ b/backend/lib/CodeGen/MachineLiveness.cpp @@ -846,11 +846,10 @@ struct LivenessRebuildPlan final { std::vector Operands; }; -[[nodiscard]] Expected liveSetIntersects(const MachineOperand &Operand, - const RegisterLaneSet &Virtual, - const RegisterUnitLaneSet &Physical, - const MachineFunction &Function, - const TargetDescription &Target) { +[[nodiscard]] Expected +liveSetIntersects(const MachineOperand &Operand, const RegisterLaneSet &Virtual, + const RegisterUnitLaneSet &Physical, const MachineFunction &Function, + const TargetDescription &Target, bool TreatReservedAsLive) { const Register *Reg = Operand.getIf(); if (Reg == nullptr || Reg->isNoRegister()) return false; @@ -860,7 +859,7 @@ struct LivenessRebuildPlan final { return std::unexpected(Lanes.error()); return Virtual.intersects(*Reg, *Lanes); } - if (isReservedPhysicalRegister(*Reg, Function, Target)) + if (TreatReservedAsLive && isReservedPhysicalRegister(*Reg, Function, Target)) return true; auto Units = physicalOperandUnits(Operand, Target); if (!Units) @@ -947,7 +946,7 @@ buildLivenessRebuildPlan(const MachineFunction &Function, const TargetDescriptio const MachineOperand *Operand = Instruction->operandAt(Index); if (Operand == nullptr || !Operand->isRegister() || !Operand->isDef()) continue; - auto IsLive = liveSetIntersects(*Operand, Virtual, Physical, Function, Target); + auto IsLive = liveSetIntersects(*Operand, Virtual, Physical, Function, Target, false); if (!IsLive) return std::unexpected(IsLive.error()); RegisterOperandFlags Flags = Operand->registerFlags(); @@ -1003,7 +1002,7 @@ buildLivenessRebuildPlan(const MachineFunction &Function, const TargetDescriptio !Operand->registerValue()->isNoRegister(); bool IsKill = false; if (IsSemanticUse) { - auto IsLive = liveSetIntersects(*Operand, Virtual, Physical, Function, Target); + auto IsLive = liveSetIntersects(*Operand, Virtual, Physical, Function, Target, true); if (!IsLive) return std::unexpected(IsLive.error()); IsKill = !*IsLive; diff --git a/backend/lib/CodeGen/PostRAScheduler.cpp b/backend/lib/CodeGen/PostRAScheduler.cpp index 204f05e..6a91239 100644 --- a/backend/lib/CodeGen/PostRAScheduler.cpp +++ b/backend/lib/CodeGen/PostRAScheduler.cpp @@ -182,7 +182,7 @@ buildBlockLivenessRepairPlan(MachineBasicBlock &Block, const TargetDescription & auto Units = physicalOperandUnits(*Operand, Target); if (!Units) return std::unexpected(Units.error()); - if (!isReservedPhysicalRegister(*Reg, Block.function(), Target) && !intersects(Live, *Units)) + if (!intersects(Live, *Units)) Update.Flags.set(RegisterOperandFlag::Dead); } -- cgit v1.2.3