mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
Rephrase the speculating scan of the conditional BB to be phrased in
terms of cost rather than hoisting a single instruction. This does *not* change the cost model! We still set the cost threshold at 1 here, it's just that we track it by accumulating cost rather than by storing an instruction. The primary advantage is that we no longer leave no-op intrinsics in the basic block. For example, this will now move both debug info intrinsics and a single instruction, instead of only moving the instruction and leaving a basic block with nothing bug debug info intrinsics in it, and those intrinsics now no longer ordered correctly with the hoisted value. Instead, we now splice the entire conditional basic block's instruction sequence. This also places the code for checking the safety of hoisting next to the code computing the cost. Currently, the only observable side-effect of this change is that debug info intrinsics are no longer abandoned. I'm not sure how to craft a test case for this, and my real goal was the refactoring, but I'll talk to Dave or Eric about how to add a test case for this. llvm-svn: 173339
This commit is contained in:
parent
fb0650e49e
commit
3a2e7d9dea
@ -1387,34 +1387,31 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB) {
|
||||
}
|
||||
assert(EndBB == BI->getSuccessor(!Invert) && "No edge from to end block");
|
||||
|
||||
// Only speculatively execution a single instruction (not counting the
|
||||
// terminator) for now.
|
||||
Instruction *HInst = NULL;
|
||||
Instruction *Term = ThenBB->getTerminator();
|
||||
for (BasicBlock::iterator BBI = ThenBB->begin(), BBE = ThenBB->end();
|
||||
unsigned SpeculationCost = 0;
|
||||
for (BasicBlock::iterator BBI = ThenBB->begin(),
|
||||
BBE = llvm::prior(ThenBB->end());
|
||||
BBI != BBE; ++BBI) {
|
||||
Instruction *I = BBI;
|
||||
// Skip debug info.
|
||||
if (isa<DbgInfoIntrinsic>(I)) continue;
|
||||
if (I == Term) break;
|
||||
if (isa<DbgInfoIntrinsic>(I))
|
||||
continue;
|
||||
|
||||
if (HInst)
|
||||
// Only speculatively execution a single instruction (not counting the
|
||||
// terminator) for now.
|
||||
++SpeculationCost;
|
||||
if (SpeculationCost > 1)
|
||||
return false;
|
||||
HInst = I;
|
||||
}
|
||||
|
||||
// Check the instruction to be hoisted, if there is one.
|
||||
if (HInst) {
|
||||
// Don't hoist the instruction if it's unsafe or expensive.
|
||||
if (!isSafeToSpeculativelyExecute(HInst))
|
||||
if (!isSafeToSpeculativelyExecute(I))
|
||||
return false;
|
||||
if (ComputeSpeculationCost(HInst) > PHINodeFoldingThreshold)
|
||||
if (ComputeSpeculationCost(I) > PHINodeFoldingThreshold)
|
||||
return false;
|
||||
|
||||
// Do not hoist the instruction if any of its operands are defined but not
|
||||
// used in this BB. The transformation will prevent the operand from
|
||||
// being sunk into the use block.
|
||||
for (User::op_iterator i = HInst->op_begin(), e = HInst->op_end();
|
||||
for (User::op_iterator i = I->op_begin(), e = I->op_end();
|
||||
i != e; ++i) {
|
||||
Instruction *OpI = dyn_cast<Instruction>(*i);
|
||||
if (OpI && OpI->getParent() == BB &&
|
||||
@ -1445,7 +1442,7 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB) {
|
||||
// An unfolded ConstantExpr could end up getting expanded into
|
||||
// Instructions. Don't speculate this and another instruction at
|
||||
// the same time.
|
||||
if (HInst)
|
||||
if (SpeculationCost > 0)
|
||||
return false;
|
||||
if (!isSafeToSpeculativelyExecute(CE))
|
||||
return false;
|
||||
@ -1461,9 +1458,9 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB) {
|
||||
// If we get here, we can hoist the instruction and if-convert.
|
||||
DEBUG(dbgs() << "SPECULATIVELY EXECUTING BB" << *ThenBB << "\n";);
|
||||
|
||||
// Hoist the instruction.
|
||||
if (HInst)
|
||||
BB->getInstList().splice(BI, ThenBB->getInstList(), HInst);
|
||||
// Hoist the instructions.
|
||||
BB->getInstList().splice(BI, ThenBB->getInstList(), ThenBB->begin(),
|
||||
llvm::prior(ThenBB->end()));
|
||||
|
||||
// Insert selects and rewrite the PHI operands.
|
||||
IRBuilder<true, NoFolder> Builder(BI);
|
||||
|
Loading…
Reference in New Issue
Block a user