From: Davide Italiano Date: Sat, 17 Jun 2017 00:56:27 +0000 (+0000) Subject: [SelectionDAG] Update Loop info after splitting critical edges. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1cea15532e77255c6894e6be156e24dbf1e959dd;p=llvm [SelectionDAG] Update Loop info after splitting critical edges. The analysis is expected to be preserved by SelectionDAG. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305621 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index dcccd17bb98..f711ca71f79 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -337,12 +337,13 @@ void SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) const { /// 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(BB.begin()); @@ -368,7 +369,7 @@ static void SplitCriticalSideEffectEdges(Function &Fn, DominatorTree *DT) { // 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::runOnMachineFunction(MachineFunction &mf) { ORE = make_unique(&Fn); auto *DTWP = getAnalysisIfAvailable(); DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr; + auto *LIWP = getAnalysisIfAvailable(); + LoopInfo *LI = LIWP ? &LIWP->getLoopInfo() : nullptr; DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n"); - SplitCriticalSideEffectEdges(const_cast(Fn), DT); + SplitCriticalSideEffectEdges(const_cast(Fn), DT, LI); CurDAG->init(*MF, *ORE); FuncInfo->set(Fn, *MF, CurDAG); diff --git a/test/CodeGen/X86/pr33396.ll b/test/CodeGen/X86/pr33396.ll new file mode 100644 index 00000000000..b2053a4ea33 --- /dev/null +++ b/test/CodeGen/X86/pr33396.ll @@ -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" + +@global = external global [2 x i8], align 2 +@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 +}