[llvm] [LoopVectorize] LLVM fails to vectorise loops with multi-bool varables (PR #89226)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 02:49:54 PDT 2024
================
@@ -635,14 +635,57 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
return InstDesc(Select, Prev.getRecKind());
}
+ SelectInst *SI = dyn_cast<SelectInst>(I);
+ Instruction *Cmp = nullptr;
+
+ if (SI) {
+ // Check that SelectInst is related to the this PHI reduction.
+ bool HasOrigPhiUser = false;
+ bool SelectNonPHIUserInLoop = false;
+ for (User *U : SI->users()) {
+ Instruction *Inst = dyn_cast<Instruction>(U);
+ if (!Inst)
+ continue;
+ if (Inst == OrigPhi) {
+ HasOrigPhiUser = true;
+ } else {
+ if (Loop->contains(Inst->getParent()))
+ SelectNonPHIUserInLoop = true;
+ }
+ }
+ Cmp = dyn_cast<CmpInst>(SI->getOperand(0));
+ // Checking the current CmpInst is safe as a recurrent reduction.
+ if (Cmp && !Cmp->hasOneUse() && HasOrigPhiUser && !SelectNonPHIUserInLoop) {
+ bool IsSafeCMP = true;
+ for (User *U : Cmp->users()) {
+ Instruction *UInst = dyn_cast<Instruction>(U);
+ if (!UInst)
+ continue;
+ if (SelectInst *SI1 = dyn_cast<SelectInst>(U)) {
+ if (!llvm::all_of(SI1->users(), [Loop](User *USI) {
----------------
sdesmalen-arm wrote:
Having a loop that goes through all users of all users of the Compare seems rather expensive.
https://github.com/llvm/llvm-project/pull/89226
More information about the llvm-commits
mailing list