Skip to content

Commit 3cdd86b

Browse files
authored
[SLP][REVEC] Make GetMinMaxCost support FixedVectorType when REVEC is enabled. (#115417)
1 parent d6e65a6 commit 3cdd86b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10986,7 +10986,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1098610986
// If the selects are the only uses of the compares, they will be
1098710987
// dead and we can adjust the cost by removing their cost.
1098810988
if (VI && SelectOnly) {
10989-
assert(!Ty->isVectorTy() && "Expected only for scalar type.");
10989+
assert((!Ty->isVectorTy() || SLPReVec) &&
10990+
"Expected only for scalar type.");
1099010991
auto *CI = cast<CmpInst>(VI->getOperand(0));
1099110992
IntrinsicCost -= TTI->getCmpSelInstrCost(
1099210993
CI->getOpcode(), Ty, Builder.getInt1Ty(), CI->getPredicate(),

llvm/test/Transforms/SLPVectorizer/RISCV/revec.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,43 @@ entry:
9494
%23 = fcmp ogt <8 x float> zeroinitializer, %19
9595
ret void
9696
}
97+
98+
define void @test3(float %0) {
99+
; CHECK-LABEL: @test3(
100+
; CHECK-NEXT: entry:
101+
; CHECK-NEXT: br label [[FOR_BODY_LR_PH:%.*]]
102+
; CHECK: for.body.lr.ph:
103+
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x float> @llvm.vector.insert.v4f32.v2f32(<4 x float> poison, <2 x float> zeroinitializer, i64 0)
104+
; CHECK-NEXT: [[TMP2:%.*]] = call <4 x float> @llvm.vector.insert.v4f32.v2f32(<4 x float> [[TMP1]], <2 x float> zeroinitializer, i64 2)
105+
; CHECK-NEXT: br i1 false, label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY:%.*]]
106+
; CHECK: for.cond.cleanup:
107+
; CHECK-NEXT: [[TMP3:%.*]] = phi <4 x float> [ [[TMP2]], [[FOR_BODY_LR_PH]] ], [ [[TMP10:%.*]], [[FOR_BODY]] ]
108+
; CHECK-NEXT: ret void
109+
; CHECK: for.body:
110+
; CHECK-NEXT: [[TMP4:%.*]] = load <2 x float>, ptr null, align 4
111+
; CHECK-NEXT: [[TMP5:%.*]] = fcmp olt <2 x float> zeroinitializer, [[TMP4]]
112+
; CHECK-NEXT: [[TMP6:%.*]] = call <4 x i1> @llvm.vector.insert.v4i1.v2i1(<4 x i1> poison, <2 x i1> splat (i1 true), i64 0)
113+
; CHECK-NEXT: [[TMP7:%.*]] = call <4 x i1> @llvm.vector.insert.v4i1.v2i1(<4 x i1> [[TMP6]], <2 x i1> [[TMP5]], i64 2)
114+
; CHECK-NEXT: [[TMP8:%.*]] = call <4 x float> @llvm.vector.insert.v4f32.v2f32(<4 x float> poison, <2 x float> [[TMP4]], i64 0)
115+
; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x float> [[TMP8]], <4 x float> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
116+
; CHECK-NEXT: [[TMP10]] = select <4 x i1> [[TMP7]], <4 x float> [[TMP9]], <4 x float> [[TMP2]]
117+
; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
118+
;
119+
entry:
120+
br label %for.body.lr.ph
121+
122+
for.body.lr.ph:
123+
br i1 false, label %for.cond.cleanup, label %for.body
124+
125+
for.cond.cleanup: ; preds = %for.body, %for.body.lr.ph
126+
%1 = phi <2 x float> [ zeroinitializer, %for.body.lr.ph ], [ %5, %for.body ]
127+
%2 = phi <2 x float> [ zeroinitializer, %for.body.lr.ph ], [ %6, %for.body ]
128+
ret void
129+
130+
for.body:
131+
%3 = load <2 x float>, ptr null, align 4
132+
%4 = fcmp olt <2 x float> zeroinitializer, %3
133+
%5 = select <2 x i1> <i1 true, i1 true>, <2 x float> %3, <2 x float> zeroinitializer
134+
%6 = select <2 x i1> %4, <2 x float> %3, <2 x float> zeroinitializer
135+
br label %for.cond.cleanup
136+
}

0 commit comments

Comments
 (0)