Skip to content

Commit 26fe800

Browse files
Dinar TemirbulatovDinar Temirbulatov
authored andcommitted
Update tests.
1 parent 2f76ef9 commit 26fe800

File tree

6 files changed

+432
-274
lines changed

6 files changed

+432
-274
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -635,57 +635,13 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
635635
return InstDesc(Select, Prev.getRecKind());
636636
}
637637

638-
SelectInst *SI = dyn_cast<SelectInst>(I);
639-
Instruction *Cmp = nullptr;
640-
641-
if (SI) {
642-
// Check that SelectInst is related to the this PHI reduction.
643-
bool HasOrigPhiUser = false;
644-
bool SelectNonPHIUserInLoop = false;
645-
for (User *U : SI->users()) {
646-
Instruction *Inst = dyn_cast<Instruction>(U);
647-
if (!Inst)
648-
continue;
649-
if (Inst == OrigPhi) {
650-
HasOrigPhiUser = true;
651-
} else {
652-
if (Loop->contains(Inst->getParent()))
653-
SelectNonPHIUserInLoop = true;
654-
}
655-
}
656-
Cmp = dyn_cast<CmpInst>(SI->getOperand(0));
657-
// Checking the current CmpInst is safe as a recurrent reduction.
658-
if (Cmp && !Cmp->hasOneUse() && HasOrigPhiUser && !SelectNonPHIUserInLoop) {
659-
bool IsSafeCMP = true;
660-
for (User *U : Cmp->users()) {
661-
Instruction *UInst = dyn_cast<Instruction>(U);
662-
if (!UInst)
663-
continue;
664-
if (SelectInst *SI1 = dyn_cast<SelectInst>(U)) {
665-
if (!llvm::all_of(SI1->users(), [Loop](User *USI) {
666-
Instruction *Inst1 = dyn_cast<Instruction>(USI);
667-
if (!Inst1 || !Loop->contains(Inst1->getParent()) ||
668-
isa<PHINode>(Inst1))
669-
return true;
670-
return false;
671-
}))
672-
IsSafeCMP = false;
673-
}
674-
if (IsSafeCMP && !isa<BranchInst>(UInst) && !isa<SelectInst>(UInst) &&
675-
Loop->contains(UInst->getParent()))
676-
IsSafeCMP = false;
677-
}
678-
if (!IsSafeCMP)
679-
Cmp = nullptr;
680-
}
681-
}
682-
683-
// Only match select with single use cmp condition.
684-
if (!Cmp && !match(I, m_Select(m_OneUse(m_Cmp(Pred, m_Value(), m_Value())),
685-
m_Value(), m_Value())))
638+
if (!match(I,
639+
m_Select(m_Cmp(Pred, m_Value(), m_Value()), m_Value(), m_Value())))
686640
return InstDesc(false, I);
687641

642+
SelectInst *SI = cast<SelectInst>(I);
688643
Value *NonPhi = nullptr;
644+
689645
if (OrigPhi == dyn_cast<PHINode>(SI->getTrueValue()))
690646
NonPhi = SI->getFalseValue();
691647
else if (OrigPhi == dyn_cast<PHINode>(SI->getFalseValue()))

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ static bool isTLIScalarize(const TargetLibraryInfo &TLI, const CallInst &CI) {
787787

788788
bool LoopVectorizationLegality::canVectorizeInstrs() {
789789
BasicBlock *Header = TheLoop->getHeader();
790-
DenseMap<Instruction *, unsigned> MultiCmpsRed;
791790

792791
// For each block in the loop.
793792
for (BasicBlock *BB : TheLoop->blocks()) {
@@ -831,20 +830,6 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
831830
Requirements->addExactFPMathInst(RedDes.getExactFPMathInst());
832831
AllowedExit.insert(RedDes.getLoopExitInstr());
833832
Reductions[Phi] = RedDes;
834-
CmpInst *Cmp = nullptr;
835-
for (Value *V :
836-
{Phi->getIncomingValue(0), Phi->getIncomingValue(1)}) {
837-
if (Instruction *SI = dyn_cast<SelectInst>(V))
838-
Cmp = dyn_cast<CmpInst>(SI->getOperand(0));
839-
}
840-
RecurKind Kind = RedDes.getRecurrenceKind();
841-
if (Cmp && !Cmp->hasOneUse() &&
842-
(Kind == RecurKind::IAnyOf || Kind == RecurKind::FAnyOf)) {
843-
if (MultiCmpsRed.contains(Cmp))
844-
MultiCmpsRed[Cmp]++;
845-
else
846-
MultiCmpsRed[Cmp] = 1;
847-
}
848833
continue;
849834
}
850835

@@ -1060,23 +1045,6 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
10601045
}
10611046
}
10621047

1063-
// Make sure that all compare instruction users are recurrent if in loop's BB.
1064-
if (MultiCmpsRed.size() > 0) {
1065-
auto Blocks = TheLoop->getBlocksVector();
1066-
for (auto const &C : MultiCmpsRed) {
1067-
Instruction *Cmp = C.first;
1068-
unsigned Counter = 0;
1069-
for (User *U : Cmp->users()) {
1070-
SelectInst *Inst = dyn_cast<SelectInst>(U);
1071-
if (Inst && std::find(Blocks.begin(), Blocks.end(),
1072-
Inst->getParent()) != Blocks.end())
1073-
Counter++;
1074-
}
1075-
if (Counter != C.second)
1076-
return false;
1077-
}
1078-
}
1079-
10801048
// Now we know the widest induction type, check if our found induction
10811049
// is the same size. If it's not, unset it here and InnerLoopVectorizer
10821050
// will create another.

llvm/test/Transforms/LoopVectorize/AArch64/select-costs.ll

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ define void @selects_1(ptr nocapture %dst, i32 %A, i32 %B, i32 %C, i32 %N) {
1313
; CHECK: LV: Found an estimated cost of 1 for VF 4 For instruction: %cond6 = select i1 %cmp2, i32 30, i32 %and
1414
; CHECK: LV: Found an estimated cost of 1 for VF 4 For instruction: %cond11 = select i1 %cmp7, i32 %cond, i32 %cond6
1515

16-
; CHECK-LABEL: define void @selects_1(
17-
; CHECK: vector.body:
18-
; CHECK: select <4 x i1>
19-
2016
entry:
2117
%cmp26 = icmp sgt i32 %N, 0
2218
br i1 %cmp26, label %for.body.preheader, label %for.cond.cleanup
@@ -47,3 +43,47 @@ for.cond.cleanup.loopexit: ; preds = %for.body
4743
for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
4844
ret void
4945
}
46+
47+
define i32 @multi_user_cmp(ptr readonly %a, i32 noundef %n) {
48+
; CHECK: LV: Found an estimated cost of 0 for VF 16 For instruction: %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
49+
; CHECK-NEXT: LV: Found an estimated cost of 0 for VF 16 For instruction: %all.0.off010 = phi i1 [ true, %entry ], [ %all.0.off0., %for.body ]
50+
; CHECK-NEXT: LV: Found an estimated cost of 0 for VF 16 For instruction: %any.0.off09 = phi i1 [ false, %entry ], [ %.any.0.off0, %for.body ]
51+
; CHECK-NEXT: LV: Found an estimated cost of 0 for VF 16 For instruction: %arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv
52+
; CHECK-NEXT: LV: Found an estimated cost of 4 for VF 16 For instruction: %load1 = load float, ptr %arrayidx, align 4
53+
; CHECK-NEXT: LV: Found an estimated cost of 4 for VF 16 For instruction: %cmp1 = fcmp olt float %load1, 0.000000e+00
54+
; CHECK-NEXT: LV: Found an estimated cost of 1 for VF 16 For instruction: %.any.0.off0 = select i1 %cmp1, i1 true, i1 %any.0.off09
55+
; CHECK-NEXT: LV: Found an estimated cost of 1 for VF 16 For instruction: %all.0.off0. = select i1 %cmp1, i1 %all.0.off010, i1 false
56+
; CHECK-NEXT: LV: Found an estimated cost of 1 for VF 16 For instruction: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
57+
; CHECK-NEXT: LV: Found an estimated cost of 1 for VF 16 For instruction: %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
58+
; CHECK-NEXT: LV: Found an estimated cost of 0 for VF 16 For instruction: br i1 %exitcond.not, label %exit, label %for.body
59+
; CHECK-NEXT: LV: Vector loop of width 16 costs: 0.
60+
entry:
61+
%wide.trip.count = zext nneg i32 %n to i64
62+
br label %for.body
63+
64+
for.body:
65+
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
66+
%all.0.off010 = phi i1 [ true, %entry ], [ %all.0.off0., %for.body ]
67+
%any.0.off09 = phi i1 [ false, %entry ], [ %.any.0.off0, %for.body ]
68+
%arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv
69+
%load1 = load float, ptr %arrayidx, align 4
70+
%cmp1 = fcmp olt float %load1, 0.000000e+00
71+
%.any.0.off0 = select i1 %cmp1, i1 true, i1 %any.0.off09
72+
%all.0.off0. = select i1 %cmp1, i1 %all.0.off010, i1 false
73+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
74+
%exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
75+
br i1 %exitcond.not, label %exit, label %for.body
76+
77+
exit:
78+
%0 = select i1 %.any.0.off0, i32 2, i32 3
79+
%1 = select i1 %all.0.off0., i32 1, i32 %0
80+
ret i32 %1
81+
}
82+
83+
; CHECK-LABEL: define void @selects_1(
84+
; CHECK: vector.body:
85+
; CHECK: select <4 x i1>
86+
87+
; CHECK-LABEL: define i32 @multi_user_cmp(
88+
; CHECK: vector.body:
89+
; CHECK: %index = phi i64

llvm/test/Transforms/LoopVectorize/AArch64/select-multi-cmp.ll

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)