mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-06 23:31:48 +00:00
Use a loop to simplify the runtime unrolling prologue.
Runtime unrolling will create a prologue to execute the extra iterations which is can't divided by the unroll factor. It generates an if-then-else sequence to jump into a factor -1 times unrolled loop body, like extraiters = tripcount % loopfactor if (extraiters == 0) jump Loop: if (extraiters == loopfactor) jump L1 if (extraiters == loopfactor-1) jump L2 ... L1: LoopBody; L2: LoopBody; ... if tripcount < loopfactor jump End Loop: ... End: It means if the unroll factor is 4, the loop body will be 7 times unrolled, 3 are in loop prologue, and 4 are in the loop. This commit is to use a loop to execute the extra iterations in prologue, like extraiters = tripcount % loopfactor if (extraiters == 0) jump Loop: else jump Prol Prol: LoopBody; extraiters -= 1 // Omitted if unroll factor is 2. if (extraiters != 0) jump Prol: // Omitted if unroll factor is 2. if (tripcount < loopfactor) jump End Loop: ... End: Then when unroll factor is 4, the loop body will be copied by only 5 times, 1 in the prologue loop, 4 in the original loop. And if the unroll factor is 2, new loop won't be created, just as the original solution. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
017c6111a8
commit
dbaeb6e7cb
@ -28,6 +28,7 @@
|
|||||||
#include "llvm/Analysis/ScalarEvolution.h"
|
#include "llvm/Analysis/ScalarEvolution.h"
|
||||||
#include "llvm/Analysis/ScalarEvolutionExpander.h"
|
#include "llvm/Analysis/ScalarEvolutionExpander.h"
|
||||||
#include "llvm/IR/BasicBlock.h"
|
#include "llvm/IR/BasicBlock.h"
|
||||||
|
#include "llvm/IR/Metadata.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||||
@ -57,7 +58,7 @@ STATISTIC(NumRuntimeUnrolled,
|
|||||||
static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
|
static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
|
||||||
BasicBlock *LastPrologBB, BasicBlock *PrologEnd,
|
BasicBlock *LastPrologBB, BasicBlock *PrologEnd,
|
||||||
BasicBlock *OrigPH, BasicBlock *NewPH,
|
BasicBlock *OrigPH, BasicBlock *NewPH,
|
||||||
ValueToValueMapTy &LVMap, Pass *P) {
|
ValueToValueMapTy &VMap, Pass *P) {
|
||||||
BasicBlock *Latch = L->getLoopLatch();
|
BasicBlock *Latch = L->getLoopLatch();
|
||||||
assert(Latch && "Loop must have a latch");
|
assert(Latch && "Loop must have a latch");
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
|
|||||||
Value *V = PN->getIncomingValueForBlock(Latch);
|
Value *V = PN->getIncomingValueForBlock(Latch);
|
||||||
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
if (Instruction *I = dyn_cast<Instruction>(V)) {
|
||||||
if (L->contains(I)) {
|
if (L->contains(I)) {
|
||||||
V = LVMap[I];
|
V = VMap[I];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Adding a value to the new PHI node from the last prolog block
|
// Adding a value to the new PHI node from the last prolog block
|
||||||
@ -127,76 +128,122 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a clone of the blocks in a loop and connect them together.
|
/// Create a clone of the blocks in a loop and connect them together.
|
||||||
/// This function doesn't create a clone of the loop structure.
|
/// If UnrollProlog is true, loop structure will not be cloned, otherwise a new
|
||||||
|
/// loop will be created including all cloned blocks, and the iterator of it
|
||||||
|
/// switches to count NewIter down to 0.
|
||||||
///
|
///
|
||||||
/// There are two value maps that are defined and used. VMap is
|
static void CloneLoopBlocks(Loop *L, Value *NewIter, const bool UnrollProlog,
|
||||||
/// for the values in the current loop instance. LVMap contains
|
BasicBlock *InsertTop, BasicBlock *InsertBot,
|
||||||
/// the values from the last loop instance. We need the LVMap values
|
|
||||||
/// to update the initial values for the current loop instance.
|
|
||||||
///
|
|
||||||
static void CloneLoopBlocks(Loop *L,
|
|
||||||
bool FirstCopy,
|
|
||||||
BasicBlock *InsertTop,
|
|
||||||
BasicBlock *InsertBot,
|
|
||||||
std::vector<BasicBlock *> &NewBlocks,
|
std::vector<BasicBlock *> &NewBlocks,
|
||||||
LoopBlocksDFS &LoopBlocks,
|
LoopBlocksDFS &LoopBlocks, ValueToValueMapTy &VMap,
|
||||||
ValueToValueMapTy &VMap,
|
|
||||||
ValueToValueMapTy &LVMap,
|
|
||||||
LoopInfo *LI) {
|
LoopInfo *LI) {
|
||||||
|
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
BasicBlock *Preheader = L->getLoopPreheader();
|
||||||
BasicBlock *Header = L->getHeader();
|
BasicBlock *Header = L->getHeader();
|
||||||
BasicBlock *Latch = L->getLoopLatch();
|
BasicBlock *Latch = L->getLoopLatch();
|
||||||
Function *F = Header->getParent();
|
Function *F = Header->getParent();
|
||||||
LoopBlocksDFS::RPOIterator BlockBegin = LoopBlocks.beginRPO();
|
LoopBlocksDFS::RPOIterator BlockBegin = LoopBlocks.beginRPO();
|
||||||
LoopBlocksDFS::RPOIterator BlockEnd = LoopBlocks.endRPO();
|
LoopBlocksDFS::RPOIterator BlockEnd = LoopBlocks.endRPO();
|
||||||
|
Loop *NewLoop = 0;
|
||||||
|
Loop *ParentLoop = L->getParentLoop();
|
||||||
|
if (!UnrollProlog) {
|
||||||
|
NewLoop = new Loop();
|
||||||
|
if (ParentLoop)
|
||||||
|
ParentLoop->addChildLoop(NewLoop);
|
||||||
|
else
|
||||||
|
LI->addTopLevelLoop(NewLoop);
|
||||||
|
}
|
||||||
|
|
||||||
// For each block in the original loop, create a new copy,
|
// For each block in the original loop, create a new copy,
|
||||||
// and update the value map with the newly created values.
|
// and update the value map with the newly created values.
|
||||||
for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
|
for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
|
||||||
BasicBlock *NewBB = CloneBasicBlock(*BB, VMap, ".unr", F);
|
BasicBlock *NewBB = CloneBasicBlock(*BB, VMap, ".prol", F);
|
||||||
NewBlocks.push_back(NewBB);
|
NewBlocks.push_back(NewBB);
|
||||||
|
|
||||||
if (Loop *ParentLoop = L->getParentLoop())
|
if (NewLoop)
|
||||||
|
NewLoop->addBasicBlockToLoop(NewBB, LI->getBase());
|
||||||
|
else if (ParentLoop)
|
||||||
ParentLoop->addBasicBlockToLoop(NewBB, LI->getBase());
|
ParentLoop->addBasicBlockToLoop(NewBB, LI->getBase());
|
||||||
|
|
||||||
VMap[*BB] = NewBB;
|
VMap[*BB] = NewBB;
|
||||||
if (Header == *BB) {
|
if (Header == *BB) {
|
||||||
// For the first block, add a CFG connection to this newly
|
// For the first block, add a CFG connection to this newly
|
||||||
// created block
|
// created block.
|
||||||
InsertTop->getTerminator()->setSuccessor(0, NewBB);
|
InsertTop->getTerminator()->setSuccessor(0, NewBB);
|
||||||
|
|
||||||
// Change the incoming values to the ones defined in the
|
}
|
||||||
// previously cloned loop.
|
if (Latch == *BB) {
|
||||||
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
|
// For the last block, if UnrollProlog is true, create a direct jump to
|
||||||
PHINode *NewPHI = cast<PHINode>(VMap[I]);
|
// InsertBot. If not, create a loop back to cloned head.
|
||||||
if (FirstCopy) {
|
VMap.erase((*BB)->getTerminator());
|
||||||
// We replace the first phi node with the value from the preheader
|
BasicBlock *FirstLoopBB = cast<BasicBlock>(VMap[Header]);
|
||||||
VMap[I] = NewPHI->getIncomingValueForBlock(Preheader);
|
BranchInst *LatchBR = cast<BranchInst>(NewBB->getTerminator());
|
||||||
NewBB->getInstList().erase(NewPHI);
|
if (UnrollProlog) {
|
||||||
|
LatchBR->eraseFromParent();
|
||||||
|
BranchInst::Create(InsertBot, NewBB);
|
||||||
} else {
|
} else {
|
||||||
// Update VMap with values from the previous block
|
PHINode *NewIdx = PHINode::Create(NewIter->getType(), 2, "prol.iter",
|
||||||
unsigned idx = NewPHI->getBasicBlockIndex(Latch);
|
FirstLoopBB->getFirstNonPHI());
|
||||||
Value *InVal = NewPHI->getIncomingValue(idx);
|
IRBuilder<> Builder(LatchBR);
|
||||||
if (Instruction *I = dyn_cast<Instruction>(InVal))
|
Value *IdxSub =
|
||||||
if (L->contains(I))
|
Builder.CreateSub(NewIdx, ConstantInt::get(NewIdx->getType(), 1),
|
||||||
InVal = LVMap[InVal];
|
NewIdx->getName() + ".sub");
|
||||||
NewPHI->setIncomingValue(idx, InVal);
|
Value *IdxCmp =
|
||||||
NewPHI->setIncomingBlock(idx, InsertTop);
|
Builder.CreateIsNotNull(IdxSub, NewIdx->getName() + ".cmp");
|
||||||
|
BranchInst::Create(FirstLoopBB, InsertBot, IdxCmp, NewBB);
|
||||||
|
NewIdx->addIncoming(NewIter, InsertTop);
|
||||||
|
NewIdx->addIncoming(IdxSub, NewBB);
|
||||||
|
LatchBR->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Latch == *BB) {
|
// Change the incoming values to the ones defined in the preheader or
|
||||||
VMap.erase((*BB)->getTerminator());
|
// cloned loop.
|
||||||
NewBB->getTerminator()->eraseFromParent();
|
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
|
||||||
BranchInst::Create(InsertBot, NewBB);
|
PHINode *NewPHI = cast<PHINode>(VMap[I]);
|
||||||
|
if (UnrollProlog) {
|
||||||
|
VMap[I] = NewPHI->getIncomingValueForBlock(Preheader);
|
||||||
|
cast<BasicBlock>(VMap[Header])->getInstList().erase(NewPHI);
|
||||||
|
} else {
|
||||||
|
unsigned idx = NewPHI->getBasicBlockIndex(Preheader);
|
||||||
|
NewPHI->setIncomingBlock(idx, InsertTop);
|
||||||
|
BasicBlock *NewLatch = cast<BasicBlock>(VMap[Latch]);
|
||||||
|
idx = NewPHI->getBasicBlockIndex(Latch);
|
||||||
|
Value *InVal = NewPHI->getIncomingValue(idx);
|
||||||
|
NewPHI->setIncomingBlock(idx, NewLatch);
|
||||||
|
if (VMap[InVal])
|
||||||
|
NewPHI->setIncomingValue(idx, VMap[InVal]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// LastValueMap is updated with the values for the current loop
|
if (NewLoop) {
|
||||||
// which are used the next time this function is called.
|
// Add unroll disable metadata to disable future unrolling for this loop.
|
||||||
for (ValueToValueMapTy::iterator VI = VMap.begin(), VE = VMap.end();
|
SmallVector<Value *, 4> Vals;
|
||||||
VI != VE; ++VI) {
|
// Reserve first location for self reference to the LoopID metadata node.
|
||||||
LVMap[VI->first] = VI->second;
|
Vals.push_back(nullptr);
|
||||||
|
MDNode *LoopID = NewLoop->getLoopID();
|
||||||
|
if (LoopID) {
|
||||||
|
// First remove any existing loop unrolling metadata.
|
||||||
|
for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
|
||||||
|
bool IsUnrollMetadata = false;
|
||||||
|
MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
|
||||||
|
if (MD) {
|
||||||
|
const MDString *S = dyn_cast<MDString>(MD->getOperand(0));
|
||||||
|
IsUnrollMetadata = S && S->getString().startswith("llvm.loop.unroll.");
|
||||||
|
}
|
||||||
|
if (!IsUnrollMetadata) Vals.push_back(LoopID->getOperand(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMContext &Context = NewLoop->getHeader()->getContext();
|
||||||
|
SmallVector<Value *, 1> DisableOperands;
|
||||||
|
DisableOperands.push_back(MDString::get(Context, "llvm.loop.unroll.disable"));
|
||||||
|
MDNode *DisableNode = MDNode::get(Context, DisableOperands);
|
||||||
|
Vals.push_back(DisableNode);
|
||||||
|
|
||||||
|
MDNode *NewLoopID = MDNode::get(Context, Vals);
|
||||||
|
// Set operand 0 to refer to the loop id itself.
|
||||||
|
NewLoopID->replaceOperandWith(0, NewLoopID);
|
||||||
|
NewLoop->setLoopID(NewLoopID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,13 +261,11 @@ static void CloneLoopBlocks(Loop *L,
|
|||||||
///
|
///
|
||||||
/// extraiters = tripcount % loopfactor
|
/// extraiters = tripcount % loopfactor
|
||||||
/// if (extraiters == 0) jump Loop:
|
/// if (extraiters == 0) jump Loop:
|
||||||
/// if (extraiters == loopfactor) jump L1
|
/// else jump Prol
|
||||||
/// if (extraiters == loopfactor-1) jump L2
|
/// Prol: LoopBody;
|
||||||
/// ...
|
/// extraiters -= 1 // Omitted if unroll factor is 2.
|
||||||
/// L1: LoopBody;
|
/// if (extraiters != 0) jump Prol: // Omitted if unroll factor is 2.
|
||||||
/// L2: LoopBody;
|
/// if (tripcount < loopfactor) jump End
|
||||||
/// ...
|
|
||||||
/// if tripcount < loopfactor jump End
|
|
||||||
/// Loop:
|
/// Loop:
|
||||||
/// ...
|
/// ...
|
||||||
/// End:
|
/// End:
|
||||||
@ -284,26 +329,21 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
|
|||||||
IRBuilder<> B(PreHeaderBR);
|
IRBuilder<> B(PreHeaderBR);
|
||||||
Value *ModVal = B.CreateAnd(TripCount, Count - 1, "xtraiter");
|
Value *ModVal = B.CreateAnd(TripCount, Count - 1, "xtraiter");
|
||||||
|
|
||||||
// Check if for no extra iterations, then jump to unrolled loop. We have to
|
// Check if for no extra iterations, then jump to cloned/unrolled loop.
|
||||||
// check that the trip count computation didn't overflow when adding one to
|
// We have to check that the trip count computation didn't overflow when
|
||||||
// the backedge taken count.
|
// adding one to the backedge taken count.
|
||||||
Value *LCmp = B.CreateIsNotNull(ModVal, "lcmp.mod");
|
Value *LCmp = B.CreateIsNotNull(ModVal, "lcmp.mod");
|
||||||
Value *OverflowCheck = B.CreateIsNull(TripCount, "lcmp.overflow");
|
Value *OverflowCheck = B.CreateIsNull(TripCount, "lcmp.overflow");
|
||||||
Value *BranchVal = B.CreateOr(OverflowCheck, LCmp, "lcmp.or");
|
Value *BranchVal = B.CreateOr(OverflowCheck, LCmp, "lcmp.or");
|
||||||
|
|
||||||
// Branch to either the extra iterations or the unrolled loop
|
// Branch to either the extra iterations or the cloned/unrolled loop
|
||||||
// We will fix up the true branch label when adding loop body copies
|
// We will fix up the true branch label when adding loop body copies
|
||||||
BranchInst::Create(PEnd, PEnd, BranchVal, PreHeaderBR);
|
BranchInst::Create(PEnd, PEnd, BranchVal, PreHeaderBR);
|
||||||
assert(PreHeaderBR->isUnconditional() &&
|
assert(PreHeaderBR->isUnconditional() &&
|
||||||
PreHeaderBR->getSuccessor(0) == PEnd &&
|
PreHeaderBR->getSuccessor(0) == PEnd &&
|
||||||
"CFG edges in Preheader are not correct");
|
"CFG edges in Preheader are not correct");
|
||||||
PreHeaderBR->eraseFromParent();
|
PreHeaderBR->eraseFromParent();
|
||||||
|
|
||||||
ValueToValueMapTy LVMap;
|
|
||||||
Function *F = Header->getParent();
|
Function *F = Header->getParent();
|
||||||
// These variables are used to update the CFG links in each iteration
|
|
||||||
BasicBlock *CompareBB = nullptr;
|
|
||||||
BasicBlock *LastLoopBB = PH;
|
|
||||||
// Get an ordered list of blocks in the loop to help with the ordering of the
|
// Get an ordered list of blocks in the loop to help with the ordering of the
|
||||||
// cloned blocks in the prolog code
|
// cloned blocks in the prolog code
|
||||||
LoopBlocksDFS LoopBlocks(L);
|
LoopBlocksDFS LoopBlocks(L);
|
||||||
@ -314,62 +354,34 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
|
|||||||
// and generate a condition that branches to the copy depending on the
|
// and generate a condition that branches to the copy depending on the
|
||||||
// number of 'left over' iterations.
|
// number of 'left over' iterations.
|
||||||
//
|
//
|
||||||
for (unsigned leftOverIters = Count-1; leftOverIters > 0; --leftOverIters) {
|
|
||||||
std::vector<BasicBlock *> NewBlocks;
|
std::vector<BasicBlock *> NewBlocks;
|
||||||
ValueToValueMapTy VMap;
|
ValueToValueMapTy VMap;
|
||||||
|
|
||||||
// Clone all the basic blocks in the loop, but we don't clone the loop
|
// Clone all the basic blocks in the loop. If Count is 2, we don't clone
|
||||||
// This function adds the appropriate CFG connections.
|
// the loop, otherwise we create a cloned loop to execute the extra
|
||||||
CloneLoopBlocks(L, (leftOverIters == Count-1), LastLoopBB, PEnd, NewBlocks,
|
// iterations. This function adds the appropriate CFG connections.
|
||||||
LoopBlocks, VMap, LVMap, LI);
|
CloneLoopBlocks(L, ModVal, Count == 2, PH, PEnd, NewBlocks, LoopBlocks, VMap,
|
||||||
LastLoopBB = cast<BasicBlock>(VMap[Latch]);
|
LI);
|
||||||
|
|
||||||
// Insert the cloned blocks into function just before the original loop
|
// Insert the cloned blocks into function just before the original loop
|
||||||
F->getBasicBlockList().splice(PEnd, F->getBasicBlockList(),
|
F->getBasicBlockList().splice(PEnd, F->getBasicBlockList(), NewBlocks[0],
|
||||||
NewBlocks[0], F->end());
|
F->end());
|
||||||
|
|
||||||
// Generate the code for the comparison which determines if the loop
|
|
||||||
// prolog code needs to be executed.
|
|
||||||
if (leftOverIters == Count-1) {
|
|
||||||
// There is no compare block for the fall-thru case when for the last
|
|
||||||
// left over iteration
|
|
||||||
CompareBB = NewBlocks[0];
|
|
||||||
} else {
|
|
||||||
// Create a new block for the comparison
|
|
||||||
BasicBlock *NewBB = BasicBlock::Create(CompareBB->getContext(), "unr.cmp",
|
|
||||||
F, CompareBB);
|
|
||||||
if (Loop *ParentLoop = L->getParentLoop()) {
|
|
||||||
// Add the new block to the parent loop, if needed
|
|
||||||
ParentLoop->addBasicBlockToLoop(NewBB, LI->getBase());
|
|
||||||
}
|
|
||||||
|
|
||||||
// The comparison w/ the extra iteration value and branch
|
|
||||||
Type *CountTy = TripCount->getType();
|
|
||||||
Value *BranchVal = new ICmpInst(*NewBB, ICmpInst::ICMP_EQ, ModVal,
|
|
||||||
ConstantInt::get(CountTy, leftOverIters),
|
|
||||||
"un.tmp");
|
|
||||||
// Branch to either the extra iterations or the unrolled loop
|
|
||||||
BranchInst::Create(NewBlocks[0], CompareBB,
|
|
||||||
BranchVal, NewBB);
|
|
||||||
CompareBB = NewBB;
|
|
||||||
PH->getTerminator()->setSuccessor(0, NewBB);
|
|
||||||
VMap[NewPH] = CompareBB;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewrite the cloned instruction operands to use the values
|
// Rewrite the cloned instruction operands to use the values
|
||||||
// created when the clone is created.
|
// created when the clone is created.
|
||||||
for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i) {
|
for (unsigned i = 0, e = NewBlocks.size(); i != e; ++i) {
|
||||||
for (BasicBlock::iterator I = NewBlocks[i]->begin(),
|
for (BasicBlock::iterator I = NewBlocks[i]->begin(),
|
||||||
E = NewBlocks[i]->end(); I != E; ++I) {
|
E = NewBlocks[i]->end();
|
||||||
|
I != E; ++I) {
|
||||||
RemapInstruction(I, VMap,
|
RemapInstruction(I, VMap,
|
||||||
RF_NoModuleLevelChanges | RF_IgnoreMissingEntries);
|
RF_NoModuleLevelChanges | RF_IgnoreMissingEntries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Connect the prolog code to the original loop and update the
|
// Connect the prolog code to the original loop and update the
|
||||||
// PHI functions.
|
// PHI functions.
|
||||||
ConnectProlog(L, TripCount, Count, LastLoopBB, PEnd, PH, NewPH, LVMap,
|
BasicBlock *LastLoopBB = cast<BasicBlock>(VMap[Latch]);
|
||||||
|
ConnectProlog(L, TripCount, Count, LastLoopBB, PEnd, PH, NewPH, VMap,
|
||||||
LPM->getAsPass());
|
LPM->getAsPass());
|
||||||
NumRuntimeUnrolled++;
|
NumRuntimeUnrolled++;
|
||||||
return true;
|
return true;
|
||||||
|
@ -41,8 +41,7 @@ for.end: ; preds = %for.body, %entry
|
|||||||
}
|
}
|
||||||
|
|
||||||
; CHECK-LABEL: @test
|
; CHECK-LABEL: @test
|
||||||
; CHECK: unr.cmp{{.*}}:
|
; CHECK: for.body.prol{{.*}}:
|
||||||
; CHECK: for.body.unr{{.*}}:
|
|
||||||
; CHECK: for.body:
|
; CHECK: for.body:
|
||||||
; CHECK: br i1 %exitcond.7, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK: br i1 %exitcond.7, label %for.end.loopexit{{.*}}, label %for.body
|
||||||
|
|
||||||
|
@ -6,12 +6,13 @@
|
|||||||
; CHECK: %lcmp.mod = icmp ne i32 %xtraiter, 0
|
; CHECK: %lcmp.mod = icmp ne i32 %xtraiter, 0
|
||||||
; CHECK: %lcmp.overflow = icmp eq i32 %n, 0
|
; CHECK: %lcmp.overflow = icmp eq i32 %n, 0
|
||||||
; CHECK: %lcmp.or = or i1 %lcmp.overflow, %lcmp.mod
|
; CHECK: %lcmp.or = or i1 %lcmp.overflow, %lcmp.mod
|
||||||
; CHECK: br i1 %lcmp.or, label %unr.cmp
|
; CHECK: br i1 %lcmp.or, label %for.body.prol, label %for.body.preheader.split
|
||||||
|
|
||||||
; CHECK: unr.cmp{{.*}}:
|
; CHECK: for.body.prol:
|
||||||
; CHECK: for.body.unr{{.*}}:
|
; CHECK: %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %for.body.prol ], [ 0, %for.body.preheader ]
|
||||||
; CHECK: for.body:
|
; CHECK: %prol.iter.sub = sub i32 %prol.iter, 1
|
||||||
; CHECK: br i1 %exitcond.7, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK: %prol.iter.cmp = icmp ne i32 %prol.iter.sub, 0
|
||||||
|
; CHECK: br i1 %prol.iter.cmp, label %for.body.prol, label %for.body.preheader.split, !llvm.loop !0
|
||||||
|
|
||||||
define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {
|
define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {
|
||||||
entry:
|
entry:
|
||||||
@ -39,7 +40,7 @@ for.end: ; preds = %for.body, %entry
|
|||||||
; even if the -unroll-runtime is specified
|
; even if the -unroll-runtime is specified
|
||||||
|
|
||||||
; CHECK: for.body:
|
; CHECK: for.body:
|
||||||
; CHECK-NOT: for.body.unr:
|
; CHECK-NOT: for.body.prol:
|
||||||
|
|
||||||
define i32 @test1(i32* nocapture %a) nounwind uwtable readonly {
|
define i32 @test1(i32* nocapture %a) nounwind uwtable readonly {
|
||||||
entry:
|
entry:
|
||||||
@ -85,8 +86,8 @@ cond_true138:
|
|||||||
|
|
||||||
; Test run-time unrolling for a loop that counts down by -2.
|
; Test run-time unrolling for a loop that counts down by -2.
|
||||||
|
|
||||||
; CHECK: for.body.unr:
|
; CHECK: for.body.prol:
|
||||||
; CHECK: br i1 %cmp.7, label %for.cond.for.end_crit_edge{{.*}}, label %for.body
|
; CHECK: br i1 %prol.iter.cmp, label %for.body.prol, label %for.body.preheader.split
|
||||||
|
|
||||||
define zeroext i16 @down(i16* nocapture %p, i32 %len) nounwind uwtable readonly {
|
define zeroext i16 @down(i16* nocapture %p, i32 %len) nounwind uwtable readonly {
|
||||||
entry:
|
entry:
|
||||||
@ -113,3 +114,7 @@ for.end: ; preds = %for.cond.for.end_cr
|
|||||||
%res.0.lcssa = phi i16 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
|
%res.0.lcssa = phi i16 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ]
|
||||||
ret i16 %res.0.lcssa
|
ret i16 %res.0.lcssa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; CHECK: !0 = metadata !{metadata !0, metadata !1}
|
||||||
|
; CHECK: !1 = metadata !{metadata !"llvm.loop.unroll.disable"}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
; RUN: opt < %s -S -loop-unroll -unroll-runtime -unroll-count=4 | FileCheck %s
|
; RUN: opt < %s -S -loop-unroll -unroll-runtime -unroll-count=2 | FileCheck %s
|
||||||
|
|
||||||
; This tests that setting the unroll count works
|
; This tests that setting the unroll count works
|
||||||
|
|
||||||
; CHECK: unr.cmp:
|
; CHECK: for.body.prol:
|
||||||
; CHECK: for.body.unr:
|
; CHECK: br label %for.body.preheader.split
|
||||||
; CHECK: for.body:
|
; CHECK: for.body:
|
||||||
; CHECK: br i1 %exitcond.3, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK: br i1 %exitcond.1, label %for.end.loopexit.unr-lcssa, label %for.body
|
||||||
; CHECK-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body
|
||||||
|
|
||||||
define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {
|
define i32 @test(i32* nocapture %a, i32 %n) nounwind uwtable readonly {
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
; Choose a smaller, power-of-two, unroll count if the loop is too large.
|
; Choose a smaller, power-of-two, unroll count if the loop is too large.
|
||||||
; This test makes sure we're not unrolling 'odd' counts
|
; This test makes sure we're not unrolling 'odd' counts
|
||||||
|
|
||||||
; CHECK: unr.cmp:
|
; CHECK: for.body.prol:
|
||||||
; CHECK: for.body.unr:
|
|
||||||
; CHECK: for.body:
|
; CHECK: for.body:
|
||||||
; CHECK: br i1 %exitcond.3, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK: br i1 %exitcond.3, label %for.end.loopexit{{.*}}, label %for.body
|
||||||
; CHECK-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body
|
; CHECK-NOT: br i1 %exitcond.4, label %for.end.loopexit{{.*}}, label %for.body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user