[SelectionDAG] Update Loop info after splitting critical edges.

The analysis is expected to be preserved by SelectionDAG.

llvm-svn: 305621
This commit is contained in:
Davide Italiano 2017-06-17 00:56:27 +00:00
parent 8ca265f4a1
commit 9382c5560b
2 changed files with 36 additions and 6 deletions

View File

@ -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<PHINode>(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<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);

View File

@ -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
}