Skip to content

Commit 5b01b8c

Browse files
Dinar TemirbulatovDinar Temirbulatov
authored andcommitted
Changed multi_user_cmp_max() function to use llvm.smax.i32 intrinsic,
Replaced std::find(Blocks.begin(), Blocks.end(),... to Loop->contains(Inst->getParent()), added comments.
1 parent d1f19c5 commit 5b01b8c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,42 +639,40 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
639639
Instruction *Cmp = nullptr;
640640

641641
if (SI) {
642+
// Check that SelectInst is related to the this PHI reduction.
642643
bool HasOrigPhiUser = false;
643644
bool SelectNonPHIUserInLoop = false;
644-
auto Blocks = Loop->getBlocksVector();
645645
for (User *U : SI->users()) {
646646
Instruction *Inst = dyn_cast<Instruction>(U);
647647
if (!Inst)
648648
continue;
649649
if (Inst == OrigPhi) {
650650
HasOrigPhiUser = true;
651651
} else {
652-
if (std::find(Blocks.begin(), Blocks.end(), Inst->getParent()) !=
653-
Blocks.end())
652+
if (Loop->contains(Inst->getParent()))
654653
SelectNonPHIUserInLoop = true;
655654
}
656655
}
657656
Cmp = dyn_cast<CmpInst>(SI->getOperand(0));
657+
// Checking the current CmpInst is safe as a recurrent reduction.
658658
if (Cmp && !Cmp->hasOneUse() && HasOrigPhiUser && !SelectNonPHIUserInLoop) {
659659
bool IsSafeCMP = true;
660660
for (User *U : Cmp->users()) {
661661
Instruction *UInst = dyn_cast<Instruction>(U);
662662
if (!UInst)
663663
continue;
664664
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) {
666666
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))
670669
return true;
671670
return false;
672671
}))
673672
IsSafeCMP = false;
674673
}
675674
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()))
678676
IsSafeCMP = false;
679677
}
680678
if (!IsSafeCMP)

0 commit comments

Comments
 (0)