@@ -639,42 +639,40 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
639
639
Instruction *Cmp = nullptr ;
640
640
641
641
if (SI) {
642
+ // Check that SelectInst is related to the this PHI reduction.
642
643
bool HasOrigPhiUser = false ;
643
644
bool SelectNonPHIUserInLoop = false ;
644
- auto Blocks = Loop->getBlocksVector ();
645
645
for (User *U : SI->users ()) {
646
646
Instruction *Inst = dyn_cast<Instruction>(U);
647
647
if (!Inst)
648
648
continue ;
649
649
if (Inst == OrigPhi) {
650
650
HasOrigPhiUser = true ;
651
651
} else {
652
- if (std::find (Blocks.begin (), Blocks.end (), Inst->getParent ()) !=
653
- Blocks.end ())
652
+ if (Loop->contains (Inst->getParent ()))
654
653
SelectNonPHIUserInLoop = true ;
655
654
}
656
655
}
657
656
Cmp = dyn_cast<CmpInst>(SI->getOperand (0 ));
657
+ // Checking the current CmpInst is safe as a recurrent reduction.
658
658
if (Cmp && !Cmp->hasOneUse () && HasOrigPhiUser && !SelectNonPHIUserInLoop) {
659
659
bool IsSafeCMP = true ;
660
660
for (User *U : Cmp->users ()) {
661
661
Instruction *UInst = dyn_cast<Instruction>(U);
662
662
if (!UInst)
663
663
continue ;
664
664
if (SelectInst *SI1 = dyn_cast<SelectInst>(U)) {
665
- if (!llvm::all_of (SI1->users (), [Blocks ](User *USI) {
665
+ if (!llvm::all_of (SI1->users (), [Loop ](User *USI) {
666
666
Instruction *Inst1 = dyn_cast<Instruction>(USI);
667
- if (!Inst1 || (std::find (Blocks.begin (), Blocks.end (),
668
- Inst1->getParent ()) == Blocks.end () ||
669
- isa<PHINode>(Inst1)))
667
+ if (!Inst1 || !Loop->contains (Inst1->getParent ()) ||
668
+ isa<PHINode>(Inst1))
670
669
return true ;
671
670
return false ;
672
671
}))
673
672
IsSafeCMP = false ;
674
673
}
675
674
if (IsSafeCMP && !isa<BranchInst>(UInst) && !isa<SelectInst>(UInst) &&
676
- std::find (Blocks.begin (), Blocks.end (), UInst->getParent ()) !=
677
- Blocks.end ())
675
+ Loop->contains (UInst->getParent ()))
678
676
IsSafeCMP = false ;
679
677
}
680
678
if (!IsSafeCMP)
0 commit comments