AMDGPU/SI: Remove ending s_endpgm from non-void functions
[oota-llvm.git] / lib / Target / AMDGPU / SIInsertWaits.cpp
index d3b41797871ea05dbaf16c217aac4694ed46a376..94e614750d2fd6d6c476942825d7c27dfacbb4a5 100644 (file)
@@ -494,6 +494,14 @@ bool SIInsertWaits::runOnMachineFunction(MachineFunction &MF) {
 
     // Wait for everything at the end of the MBB
     Changes |= insertWait(MBB, MBB.getFirstTerminator(), LastIssued);
+
+    // Functions returning something shouldn't contain S_ENDPGM, because other
+    // bytecode will be appended after it.
+    if (!ReturnsVoid) {
+      MachineBasicBlock::iterator I = MBB.getFirstTerminator();
+      if (I != MBB.end() && I->getOpcode() == AMDGPU::S_ENDPGM)
+        I->eraseFromParent();
+    }
   }
 
   return Changes;