Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -3308,9 +3308,15 @@ auto InsPt = emitLoadM0FromVGPRLoop(TII, MRI, MBB, *LoopBB, DL, *Idx, InitResultReg, DstReg, PhiReg, TmpExec, Offset, UseGPRIdxMode, IsIndirectSrc); - - MachineBasicBlock::iterator First = RemainderBB->begin(); - BuildMI(*RemainderBB, First, DL, TII->get(MovExecOpc), Exec) + MachineBasicBlock* LandingPad = MF->CreateMachineBasicBlock(); + MachineFunction::iterator MBBI(LoopBB); + ++MBBI; + MF->insert(MBBI, LandingPad); + LoopBB->removeSuccessor(RemainderBB); + LandingPad->addSuccessor(RemainderBB); + LoopBB->addSuccessor(LandingPad); + MachineBasicBlock::iterator First = LandingPad->begin(); + BuildMI(*LandingPad, First, DL, TII->get(MovExecOpc), Exec) .addReg(SaveExec); return InsPt;