[llvm] r305621 - [SelectionDAG] Update Loop info after splitting critical edges.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 16 17:56:27 PDT 2017


Author: davide
Date: Fri Jun 16 19:56:27 2017
New Revision: 305621

URL: http://llvm.org/viewvc/llvm-project?rev=305621&view=rev
Log:
[SelectionDAG] Update Loop info after splitting critical edges.

The analysis is expected to be preserved by SelectionDAG.

Added:
    llvm/trunk/test/CodeGen/X86/pr33396.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=305621&r1=305620&r2=305621&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Jun 16 19:56:27 2017
@@ -337,12 +337,13 @@ void SelectionDAGISel::getAnalysisUsage(
 /// SplitCriticalSideEffectEdges - Look for critical edges with a PHI value that
 /// may trap on it.  In this case we have to split the edge so that the path
 /// through the predecessor block that doesn't go to the phi block doesn't
-/// execute the possibly trapping instruction. If available, we pass a
-/// dominator tree to be updated when we split critical edges. This is because
-/// SelectionDAGISel preserves the DominatorTree.
+/// execute the possibly trapping instruction. If available, we pass domtree
+/// and loop info to be updated when we split critical edges. This is because
+/// SelectionDAGISel preserves these analyses.
 /// This is required for correctness, so it must be done at -O0.
 ///
-static void SplitCriticalSideEffectEdges(Function &Fn, DominatorTree *DT) {
+static void SplitCriticalSideEffectEdges(Function &Fn, DominatorTree *DT,
+                                         LoopInfo *LI) {
   // Loop for blocks with phi nodes.
   for (BasicBlock &BB : Fn) {
     PHINode *PN = dyn_cast<PHINode>(BB.begin());
@@ -368,7 +369,7 @@ static void SplitCriticalSideEffectEdges
         // Okay, we have to split this edge.
         SplitCriticalEdge(
             Pred->getTerminator(), GetSuccessorNumber(Pred, &BB),
-            CriticalEdgeSplittingOptions(DT).setMergeIdenticalEdges());
+            CriticalEdgeSplittingOptions(DT, LI).setMergeIdenticalEdges());
         goto ReprocessBlock;
       }
   }
@@ -406,10 +407,12 @@ bool SelectionDAGISel::runOnMachineFunct
   ORE = make_unique<OptimizationRemarkEmitter>(&Fn);
   auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
   DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
+  auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
+  LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
 
   DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n");
 
-  SplitCriticalSideEffectEdges(const_cast<Function &>(Fn), DT);
+  SplitCriticalSideEffectEdges(const_cast<Function &>(Fn), DT, LI);
 
   CurDAG->init(*MF, *ORE);
   FuncInfo->set(Fn, *MF, CurDAG);

Added: llvm/trunk/test/CodeGen/X86/pr33396.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr33396.ll?rev=305621&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr33396.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pr33396.ll Fri Jun 16 19:56:27 2017
@@ -0,0 +1,27 @@
+; Make sure we don't crash because we have stale loop infos.
+; REQUIRES: asserts
+; RUN: llc -o /dev/null -verify-loop-info %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at global = external global [2 x i8], align 2
+ at global.1 = external global [2 x i8], align 2
+
+define void @patatino(i8 %tinky) {
+bb:
+  br label %bb1
+
+bb1:
+  br i1 icmp ne (i8* getelementptr ([2 x i8], [2 x i8]* @global.1, i64 0, i64 1),
+                 i8* getelementptr ([2 x i8], [2 x i8]* @global, i64 0, i64 1)), label %bb2, label %bb3
+
+bb2:
+  br label %bb3
+
+bb3:
+  %tmp = phi i32 [ 60, %bb2 ],
+                 [ sdiv (i32 60, i32 zext (i1 icmp eq (i8* getelementptr ([2 x i8], [2 x i8]* @global.1, i64 0, i64 1),
+                                           i8* getelementptr ([2 x i8], [2 x i8]* @global, i64 0, i64 1)) to i32)), %bb1 ]
+  %tmp4 = icmp slt i8 %tinky, -4
+  br label %bb1
+}




More information about the llvm-commits mailing list