forked from OSchip/llvm-project
[LV] Preserve LoopInfo when store predication is used
This was a latent bug that got exposed by the change to add LoopSimplify as a dependence to LoopLoadElimination. Since LoopInfo was corrupted after LV, LoopSimplify mis-compiled nbench in the test-suite (more details in the PR). The problem was that when we create the blocks for predicated stores we didn't add those to any loops. The original testcase for store predication provides coverage for this assuming we verify LI on the way out of LV. Fixes PR26952. llvm-svn: 263565
This commit is contained in:
parent
dfdf278ebf
commit
fdb20595a1
|
@ -259,11 +259,12 @@ ReturnInst *FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
|||
/// UnreachableInst, otherwise it branches to Tail.
|
||||
/// Returns the NewBasicBlock's terminator.
|
||||
///
|
||||
/// Updates DT if given.
|
||||
/// Updates DT and LI if given.
|
||||
TerminatorInst *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
bool Unreachable,
|
||||
MDNode *BranchWeights = nullptr,
|
||||
DominatorTree *DT = nullptr);
|
||||
DominatorTree *DT = nullptr,
|
||||
LoopInfo *LI = nullptr);
|
||||
|
||||
/// SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen,
|
||||
/// but also creates the ElseBlock.
|
||||
|
|
|
@ -709,11 +709,10 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
|||
/// UnreachableInst, otherwise it branches to Tail.
|
||||
/// Returns the NewBasicBlock's terminator.
|
||||
|
||||
TerminatorInst *llvm::SplitBlockAndInsertIfThen(Value *Cond,
|
||||
Instruction *SplitBefore,
|
||||
bool Unreachable,
|
||||
MDNode *BranchWeights,
|
||||
DominatorTree *DT) {
|
||||
TerminatorInst *
|
||||
llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
bool Unreachable, MDNode *BranchWeights,
|
||||
DominatorTree *DT, LoopInfo *LI) {
|
||||
BasicBlock *Head = SplitBefore->getParent();
|
||||
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
|
||||
TerminatorInst *HeadOldTerm = Head->getTerminator();
|
||||
|
@ -743,6 +742,12 @@ TerminatorInst *llvm::SplitBlockAndInsertIfThen(Value *Cond,
|
|||
}
|
||||
}
|
||||
|
||||
if (LI) {
|
||||
Loop *L = LI->getLoopFor(Head);
|
||||
L->addBasicBlockToLoop(ThenBlock, *LI);
|
||||
L->addBasicBlockToLoop(Tail, *LI);
|
||||
}
|
||||
|
||||
return CheckTerm;
|
||||
}
|
||||
|
||||
|
|
|
@ -3628,7 +3628,7 @@ void InnerLoopVectorizer::vectorizeLoop() {
|
|||
BasicBlock::iterator I(KV.first);
|
||||
auto *BB = SplitBlock(I->getParent(), &*std::next(I), DT, LI);
|
||||
auto *T = SplitBlockAndInsertIfThen(KV.second, &*I, /*Unreachable=*/false,
|
||||
/*BranchWeights=*/nullptr, DT);
|
||||
/*BranchWeights=*/nullptr, DT, LI);
|
||||
I->moveBefore(T);
|
||||
I->getParent()->setName("pred.store.if");
|
||||
BB->setName("pred.store.continue");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -loop-vectorize -simplifycfg < %s | FileCheck %s --check-prefix=UNROLL
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -loop-vectorize < %s | FileCheck %s --check-prefix=UNROLL-NOSIMPLIFY
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -loop-vectorize -enable-cond-stores-vec -simplifycfg < %s | FileCheck %s --check-prefix=VEC
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -loop-vectorize -enable-cond-stores-vec -simplifycfg -instcombine < %s | FileCheck %s --check-prefix=VEC-IC
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -loop-vectorize -verify-loop-info -simplifycfg < %s | FileCheck %s --check-prefix=UNROLL
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -loop-vectorize -verify-loop-info < %s | FileCheck %s --check-prefix=UNROLL-NOSIMPLIFY
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -loop-vectorize -enable-cond-stores-vec -verify-loop-info -simplifycfg < %s | FileCheck %s --check-prefix=VEC
|
||||
; RUN: opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -loop-vectorize -enable-cond-stores-vec -verify-loop-info -simplifycfg -instcombine < %s | FileCheck %s --check-prefix=VEC-IC
|
||||
|
||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-apple-macosx10.9.0"
|
||||
|
|
Loading…
Reference in New Issue