AMDGPU/SI: Remove ending s_endpgm from non-void functions
authorMarek Olsak <marek.olsak@amd.com>
Wed, 13 Jan 2016 17:23:12 +0000 (17:23 +0000)
committerMarek Olsak <marek.olsak@amd.com>
Wed, 13 Jan 2016 17:23:12 +0000 (17:23 +0000)
Reviewers: tstellarAMD, arsenm

Subscribers: arsenm

Differential Revision: http://reviews.llvm.org/D16035

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257623 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/SIInsertWaits.cpp

index d3b4179..94e6147 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;