[PATCH] D47874: [SCEVExp] Advance found insertion point until we find a non-dbg instruction.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 14 06:54:13 PDT 2018


fhahn updated this revision to Diff 151344.
fhahn retitled this revision from "[SCEVExpander] Ignore dbg info when finding insertion point." to "[SCEVExp] Advance found insertion point until we find a non-dbg instruction.".
fhahn added a comment.

I've updated the patch to add a skipDebugInstructionsForward utility. We have a very similar function defined in MachineBasicBlock.h, maybe we should consolidate those functions?

With this approach, there is one scenario where we could still get different codegen depending on debug info if there are debug intrinsics before a funclet/landingpad instruction.


https://reviews.llvm.org/D47874

Files:
  include/llvm/IR/BasicBlock.h
  lib/Analysis/ScalarEvolutionExpander.cpp


Index: lib/Analysis/ScalarEvolutionExpander.cpp
===================================================================
--- lib/Analysis/ScalarEvolutionExpander.cpp
+++ lib/Analysis/ScalarEvolutionExpander.cpp
@@ -162,7 +162,8 @@
 
   // Cast the instruction immediately after the instruction.
   Instruction *I = cast<Instruction>(V);
-  BasicBlock::iterator IP = findInsertPointAfter(I, Builder.GetInsertBlock());
+  BasicBlock::iterator IP = skipDebugInstructionsForward(
+      findInsertPointAfter(I, Builder.GetInsertBlock()));
   return ReuseOrCreateCast(I, Ty, Op, IP);
 }
 
@@ -1480,8 +1481,8 @@
       NewOps[i] = SE.getAnyExtendExpr(S->op_begin()[i], CanonicalIV->getType());
     Value *V = expand(SE.getAddRecExpr(NewOps, S->getLoop(),
                                        S->getNoWrapFlags(SCEV::FlagNW)));
-    BasicBlock::iterator NewInsertPt =
-        findInsertPointAfter(cast<Instruction>(V), Builder.GetInsertBlock());
+    BasicBlock::iterator NewInsertPt = skipDebugInstructionsForward(
+        findInsertPointAfter(cast<Instruction>(V), Builder.GetInsertBlock()));
     V = expandCodeFor(SE.getTruncateExpr(SE.getUnknown(V), Ty), nullptr,
                       &*NewInsertPt);
     return V;
Index: include/llvm/IR/BasicBlock.h
===================================================================
--- include/llvm/IR/BasicBlock.h
+++ include/llvm/IR/BasicBlock.h
@@ -430,6 +430,16 @@
   }
 };
 
+class DbgInfoIntrinsic;
+
+/// Increment \p It until it points to a non-debug instruction and return the
+/// resulting iterator.
+template <typename IterT> inline IterT skipDebugInstructionsForward(IterT It) {
+  while (isa<DbgInfoIntrinsic>(&*It))
+    It++;
+  return It;
+}
+
 // Create wrappers for C Binding types (see CBindingWrapping.h).
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47874.151344.patch
Type: text/x-patch
Size: 1835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180614/e6515ece/attachment.bin>


More information about the llvm-commits mailing list