... | ... |
@@ -546,24 +546,38 @@ namespace { |
546 | 546 |
LHS = SE->getNoopOrZeroExtend(LHS, LTy); |
547 | 547 |
RHS = SE->getNoopOrZeroExtend(RHS, LTy); |
548 | 548 |
} |
549 |
- bool checkCondition(CallInst *CI, Instruction *I) |
|
549 |
+ bool checkCond(Instruction *ICI, Instruction *I, bool equal) |
|
550 |
+ { |
|
551 |
+ for (Value::use_iterator JU=ICI->use_begin(),JUE=ICI->use_end(); |
|
552 |
+ JU != JUE; ++JU) { |
|
553 |
+ if (BranchInst *BI = dyn_cast<BranchInst>(JU)) { |
|
554 |
+ if (!BI->isConditional()) |
|
555 |
+ continue; |
|
556 |
+ BasicBlock *S = BI->getSuccessor(equal); |
|
557 |
+ if (DT->dominates(S, I->getParent())) |
|
558 |
+ return true; |
|
559 |
+ } |
|
560 |
+ if (BinaryOperator *BI = dyn_cast<BinaryOperator>(JU)) { |
|
561 |
+ if (BI->getOpcode() == Instruction::Or && |
|
562 |
+ checkCond(BI, I, equal)) |
|
563 |
+ return true; |
|
564 |
+ if (BI->getOpcode() == Instruction::And && |
|
565 |
+ checkCond(BI, I, !equal)) |
|
566 |
+ return true; |
|
567 |
+ } |
|
568 |
+ } |
|
569 |
+ return false; |
|
570 |
+ } |
|
571 |
+ |
|
572 |
+ bool checkCondition(Instruction *CI, Instruction *I) |
|
550 | 573 |
{ |
551 | 574 |
for (Value::use_iterator U=CI->use_begin(),UE=CI->use_end(); |
552 | 575 |
U != UE; ++U) { |
553 | 576 |
if (ICmpInst *ICI = dyn_cast<ICmpInst>(U)) { |
554 | 577 |
if (ICI->getOperand(0)->stripPointerCasts() == CI && |
555 | 578 |
isa<ConstantPointerNull>(ICI->getOperand(1))) { |
556 |
- for (Value::use_iterator JU=ICI->use_begin(),JUE=ICI->use_end(); |
|
557 |
- JU != JUE; ++JU) { |
|
558 |
- if (BranchInst *BI = dyn_cast<BranchInst>(JU)) { |
|
559 |
- if (!BI->isConditional()) |
|
560 |
- continue; |
|
561 |
- BasicBlock *S = BI->getSuccessor(ICI->getPredicate() == |
|
562 |
- ICmpInst::ICMP_EQ); |
|
563 |
- if (DT->dominates(S, I->getParent())) |
|
564 |
- return true; |
|
565 |
- } |
|
566 |
- } |
|
579 |
+ if (checkCond(ICI, I, ICI->getPredicate() == ICmpInst::ICMP_EQ)) |
|
580 |
+ return true; |
|
567 | 581 |
} |
568 | 582 |
} |
569 | 583 |
} |