AMDGPU: Skip debug_instr when collapsing end_cf

Based on how these are inserted, I doubt this was causing a problem in
practice.

llvm-svn: 357090
diff --git a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
index 21eecb1..f5724a7 100644
--- a/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
+++ b/llvm/lib/Target/AMDGPU/SIOptimizeExecMaskingPreRA.cpp
@@ -308,7 +308,8 @@
     }
 
     // Try to collapse adjacent endifs.
-    auto Lead = MBB.begin(), E = MBB.end();
+    auto E = MBB.end();
+    auto Lead = skipDebugInstructionsForward(MBB.begin(), E);
     if (MBB.succ_size() != 1 || Lead == E || !isEndCF(*Lead, TRI))
       continue;
 
@@ -318,14 +319,18 @@
 
     auto I = std::next(Lead);
 
-    for ( ; I != E; ++I)
+    for ( ; I != E; ++I) {
+      if (I->isDebugInstr())
+        continue;
+
       if (!TII->isSALU(*I) || I->readsRegister(AMDGPU::EXEC, TRI))
         break;
+    }
 
     if (I != E)
       continue;
 
-    const auto NextLead = Succ->begin();
+    auto NextLead = skipDebugInstructionsForward(Succ->begin(), Succ->end());
     if (NextLead == Succ->end() || !isEndCF(*NextLead, TRI) ||
         !getOrExecSource(*NextLead, *TII, MRI))
       continue;