Debug intrinsics must be skipped at the beginning and ends of blocks, lest they
authorCameron Zwarich <zwarich@apple.com>
Thu, 24 Mar 2011 16:34:59 +0000 (16:34 +0000)
committerCameron Zwarich <zwarich@apple.com>
Thu, 24 Mar 2011 16:34:59 +0000 (16:34 +0000)
affect the generated code.

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

lib/Transforms/Scalar/CodeGenPrepare.cpp

index 337a4d3c468ebc971e562f69577454cfdd2f878f..2f7ccea6e1715083ba644fc2f0c76f33b1d0008a 100644 (file)
@@ -617,7 +617,9 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
     if (&*BI != RI)
       return false;
   } else {
-    if (&*BB->begin() != RI)
+    BasicBlock::iterator BI = BB->begin();
+    while (isa<DbgInfoIntrinsic>(BI)) ++BI;
+    if (&*BI != RI)
       return false;
   }
 
@@ -641,8 +643,10 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
       BasicBlock::InstListType &InstList = (*PI)->getInstList();
       BasicBlock::InstListType::reverse_iterator RI = InstList.rbegin();
       BasicBlock::InstListType::reverse_iterator RE = InstList.rend();
-      if (++RI == RE)
+      do { ++RI; } while (RI != RE && isa<DbgInfoIntrinsic>(&*RI));
+      if (RI == RE)
         continue;
+
       CallInst *CI = dyn_cast<CallInst>(&*RI);
       if (CI && CI->use_empty() && TLI->mayBeEmittedAsTailCall(CI))
         TailCalls.push_back(CI);