parent
6b3169bb97
commit
892f167aa5
|
@ -5368,43 +5368,38 @@ bool CodeGenPrepare::sinkAndCmp(Function &F) {
|
||||||
if (!TLI || !TLI->isMaskAndBranchFoldingLegal())
|
if (!TLI || !TLI->isMaskAndBranchFoldingLegal())
|
||||||
return false;
|
return false;
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
for (Function::iterator I = F.begin(), E = F.end(); I != E; ) {
|
for (BasicBlock &BB : F) {
|
||||||
BasicBlock *BB = &*I++;
|
|
||||||
|
|
||||||
// Does this BB end with the following?
|
// Does this BB end with the following?
|
||||||
// %andVal = and %val, #single-bit-set
|
// %andVal = and %val, #single-bit-set
|
||||||
// %icmpVal = icmp %andResult, 0
|
// %icmpVal = icmp %andResult, 0
|
||||||
// br i1 %cmpVal label %dest1, label %dest2"
|
// br i1 %cmpVal label %dest1, label %dest2"
|
||||||
BranchInst *Brcc = dyn_cast<BranchInst>(BB->getTerminator());
|
BranchInst *Brcc = dyn_cast<BranchInst>(BB.getTerminator());
|
||||||
if (!Brcc || !Brcc->isConditional())
|
if (!Brcc || !Brcc->isConditional())
|
||||||
continue;
|
continue;
|
||||||
ICmpInst *Cmp = dyn_cast<ICmpInst>(Brcc->getOperand(0));
|
ICmpInst *Cmp = dyn_cast<ICmpInst>(Brcc->getOperand(0));
|
||||||
if (!Cmp || Cmp->getParent() != BB)
|
if (!Cmp || Cmp->getParent() != &BB)
|
||||||
continue;
|
continue;
|
||||||
ConstantInt *Zero = dyn_cast<ConstantInt>(Cmp->getOperand(1));
|
ConstantInt *Zero = dyn_cast<ConstantInt>(Cmp->getOperand(1));
|
||||||
if (!Zero || !Zero->isZero())
|
if (!Zero || !Zero->isZero())
|
||||||
continue;
|
continue;
|
||||||
Instruction *And = dyn_cast<Instruction>(Cmp->getOperand(0));
|
Instruction *And = dyn_cast<Instruction>(Cmp->getOperand(0));
|
||||||
if (!And || And->getOpcode() != Instruction::And || And->getParent() != BB)
|
if (!And || And->getOpcode() != Instruction::And || And->getParent() != &BB)
|
||||||
continue;
|
continue;
|
||||||
ConstantInt* Mask = dyn_cast<ConstantInt>(And->getOperand(1));
|
ConstantInt* Mask = dyn_cast<ConstantInt>(And->getOperand(1));
|
||||||
if (!Mask || !Mask->getUniqueInteger().isPowerOf2())
|
if (!Mask || !Mask->getUniqueInteger().isPowerOf2())
|
||||||
continue;
|
continue;
|
||||||
DEBUG(dbgs() << "found and; icmp ?,0; brcc\n"); DEBUG(BB->dump());
|
DEBUG(dbgs() << "found and; icmp ?,0; brcc\n"); DEBUG(BB.dump());
|
||||||
|
|
||||||
// Push the "and; icmp" for any users that are conditional branches.
|
// Push the "and; icmp" for any users that are conditional branches.
|
||||||
// Since there can only be one branch use per BB, we don't need to keep
|
// Since there can only be one branch use per BB, we don't need to keep
|
||||||
// track of which BBs we insert into.
|
// track of which BBs we insert into.
|
||||||
for (Value::use_iterator UI = Cmp->use_begin(), E = Cmp->use_end();
|
for (Use &TheUse : Cmp->uses()) {
|
||||||
UI != E; ) {
|
|
||||||
Use &TheUse = *UI;
|
|
||||||
// Find brcc use.
|
// Find brcc use.
|
||||||
BranchInst *BrccUser = dyn_cast<BranchInst>(*UI);
|
BranchInst *BrccUser = dyn_cast<BranchInst>(TheUse);
|
||||||
++UI;
|
|
||||||
if (!BrccUser || !BrccUser->isConditional())
|
if (!BrccUser || !BrccUser->isConditional())
|
||||||
continue;
|
continue;
|
||||||
BasicBlock *UserBB = BrccUser->getParent();
|
BasicBlock *UserBB = BrccUser->getParent();
|
||||||
if (UserBB == BB) continue;
|
if (UserBB == &BB) continue;
|
||||||
DEBUG(dbgs() << "found Brcc use\n");
|
DEBUG(dbgs() << "found Brcc use\n");
|
||||||
|
|
||||||
// Sink the "and; icmp" to use.
|
// Sink the "and; icmp" to use.
|
||||||
|
|
Loading…
Reference in New Issue