From 2c8eca98ec791ffe4d12ba11e8d2821c585ad7a8 Mon Sep 17 00:00:00 2001 From: Jonas Paulsson Date: Thu, 23 Jun 2016 08:13:20 +0000 Subject: [PATCH] [IfConversion] Bugfix: Don't use undef flag while adding use operands. IfConversion used to always add the undef flag when adding a use operand on a newly predicated instruction. This would be an operand for the register being conditionally redefined. Due to the undef flag, the liveness of this register prior to the predicated instruction would get lost. This patch changes this so that such use operands are added only when the register is live, without the undef flag. Reviewed by Quentin Colombet. http://reviews.llvm.org/D209077 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273545 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/IfConversion.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/IfConversion.cpp b/lib/CodeGen/IfConversion.cpp index 4cdad607f76..1f968042a37 100644 --- a/lib/CodeGen/IfConversion.cpp +++ b/lib/CodeGen/IfConversion.cpp @@ -1046,8 +1046,19 @@ void IfConverter::RemoveExtraEdges(BBInfo &BBI) { } /// Behaves like LiveRegUnits::StepForward() but also adds implicit uses to all -/// values defined in MI which are not live/used by MI. +/// values defined in MI which are also live/used by MI. static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) { + const TargetRegisterInfo *TRI = MI.getParent()->getParent() + ->getSubtarget().getRegisterInfo(); + + // Before stepping forward past MI, remember which regs were live + // before MI. This is needed to set the Undef flag only when reg is + // dead. + SparseSet LiveBeforeMI; + LiveBeforeMI.setUniverse(TRI->getNumRegs()); + for (auto &Reg : Redefs) + LiveBeforeMI.insert(Reg); + SmallVector, 4> Clobbers; Redefs.stepForward(MI, Clobbers); @@ -1061,7 +1072,8 @@ static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) { if (Op.isRegMask()) { // First handle regmasks. They clobber any entries in the mask which // means that we need a def for those registers. - MIB.addReg(Reg.first, RegState::Implicit | RegState::Undef); + if (LiveBeforeMI.count(Reg.first)) + MIB.addReg(Reg.first, RegState::Implicit); // We also need to add an implicit def of this register for the later // use to read from. @@ -1078,7 +1090,8 @@ static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) { if (Redefs.contains(Op.getReg())) Op.setIsDead(false); } - MIB.addReg(Reg.first, RegState::Implicit | RegState::Undef); + if (LiveBeforeMI.count(Reg.first)) + MIB.addReg(Reg.first, RegState::Implicit); } } -- 2.50.1