diff options
Diffstat (limited to 'lib/Target/AMDGPU/SIFixSGPRCopies.cpp')
| -rw-r--r-- | lib/Target/AMDGPU/SIFixSGPRCopies.cpp | 35 | 
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/lib/Target/AMDGPU/SIFixSGPRCopies.cpp index 6a422e70fe1f..f9d258f44a62 100644 --- a/lib/Target/AMDGPU/SIFixSGPRCopies.cpp +++ b/lib/Target/AMDGPU/SIFixSGPRCopies.cpp @@ -65,6 +65,7 @@  /// ultimately led to the creation of an illegal COPY.  //===----------------------------------------------------------------------===// +#include "llvm/ADT/DenseSet.h"  #include "AMDGPU.h"  #include "AMDGPUSubtarget.h"  #include "SIInstrInfo.h" @@ -198,6 +199,10 @@ static bool foldVGPRCopyIntoRegSequence(MachineInstr &MI,    if (!CopyUse.isCopy())      return false; +  // It is illegal to have vreg inputs to a physreg defining reg_sequence. +  if (TargetRegisterInfo::isPhysicalRegister(CopyUse.getOperand(0).getReg())) +    return false; +    const TargetRegisterClass *SrcRC, *DstRC;    std::tie(SrcRC, DstRC) = getCopyRegClasses(CopyUse, *TRI, MRI); @@ -234,8 +239,9 @@ static bool foldVGPRCopyIntoRegSequence(MachineInstr &MI,      unsigned TmpReg = MRI.createVirtualRegister(NewSrcRC); -    BuildMI(*MI.getParent(), &MI, MI.getDebugLoc(), TII->get(AMDGPU::COPY), TmpReg) -      .addOperand(MI.getOperand(I)); +    BuildMI(*MI.getParent(), &MI, MI.getDebugLoc(), TII->get(AMDGPU::COPY), +            TmpReg) +        .add(MI.getOperand(I));      MI.getOperand(I).setReg(TmpReg);    } @@ -326,6 +332,27 @@ static bool isSafeToFoldImmIntoCopy(const MachineInstr *Copy,    return true;  } +static bool predsHasDivergentTerminator(MachineBasicBlock *MBB, +                               const TargetRegisterInfo *TRI) { +  DenseSet<MachineBasicBlock*> Visited; +  SmallVector<MachineBasicBlock*, 4> Worklist(MBB->pred_begin(),  +                                              MBB->pred_end()); + +  while (!Worklist.empty()) { +    MachineBasicBlock *mbb = Worklist.back(); +    Worklist.pop_back(); + +    if (!Visited.insert(mbb).second) +      continue; +    if (hasTerminatorThatModifiesExec(*mbb, *TRI)) +      return true; + +    Worklist.insert(Worklist.end(), mbb->pred_begin(), mbb->pred_end()); +  } + +  return false; +} +  bool SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {    const SISubtarget &ST = MF.getSubtarget<SISubtarget>();    MachineRegisterInfo &MRI = MF.getRegInfo(); @@ -382,8 +409,8 @@ bool SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {            MachineBasicBlock *MBB0 = MI.getOperand(2).getMBB();            MachineBasicBlock *MBB1 = MI.getOperand(4).getMBB(); -          MachineBasicBlock *NCD = MDT->findNearestCommonDominator(MBB0, MBB1); -          if (NCD && !hasTerminatorThatModifiesExec(*NCD, *TRI)) { +          if (!predsHasDivergentTerminator(MBB0, TRI) && +              !predsHasDivergentTerminator(MBB1, TRI)) {              DEBUG(dbgs() << "Not fixing PHI for uniform branch: " << MI << '\n');              break;            }  | 
