Skip to content

Commit 493f56c

Browse files
committed
fixup! Combine formulas of NumOfVMAND
1 parent 0a55282 commit 493f56c

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,17 +1551,13 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
15511551
// vcpop.m a0, v8
15521552
// seqz a0, a0
15531553

1554-
// Scalable VT: In nxv128i1 and larger vector elements,
1554+
// Scalable VT: In nxv256i1 and larger vector elements,
15551555
// Fixed VT: If getFixedSizeInBits() >= (4 * getRealMinVLen()),
1556-
// the VMAND_MM instructions have started to be added.
1556+
// the VMAND_MM instructions have started to be added.
15571557
InstructionCost NumOfVMAND = 0;
1558-
if (LT.second.isScalableVector()) {
1559-
NumOfVMAND = (LT.first >= 2) ? (LT.first - 1) : 0;
1560-
} else {
1561-
bool IsOverflow =
1562-
LT.second.getFixedSizeInBits() == ST->getRealMinVLen();
1563-
NumOfVMAND = (IsOverflow && LT.first > 2) ? (LT.first - 2) : 0;
1564-
}
1558+
if (LT.second.isScalableVector() ||
1559+
LT.second.getFixedSizeInBits() == ST->getRealMinVLen())
1560+
NumOfVMAND = (LT.first > 2) ? (LT.first - 2) : 0;
15651561
return NumOfVMAND *
15661562
getRISCVInstructionCost(RISCV::VMAND_MM, LT.second, CostKind) +
15671563
getRISCVInstructionCost(RISCV::VMNAND_MM, LT.second, CostKind) +

llvm/test/Analysis/CostModel/RISCV/reduce-and-i1.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ define zeroext i1 @vreduce_and_nxv64i1(<vscale x 64 x i1> %v) {
204204

205205
define zeroext i1 @vreduce_and_nxv128i1(<vscale x 128 x i1> %v) {
206206
; THROUGHPUT-LABEL: 'vreduce_and_nxv128i1'
207-
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> %v)
207+
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> %v)
208208
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i1 %red
209209
;
210210
%red = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> %v)
@@ -213,7 +213,7 @@ define zeroext i1 @vreduce_and_nxv128i1(<vscale x 128 x i1> %v) {
213213

214214
define zeroext i1 @vreduce_and_nxv256i1(<vscale x 256 x i1> %v) {
215215
; THROUGHPUT-LABEL: 'vreduce_and_nxv256i1'
216-
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> %v)
216+
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> %v)
217217
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i1 %red
218218
;
219219
%red = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> %v)
@@ -222,7 +222,7 @@ define zeroext i1 @vreduce_and_nxv256i1(<vscale x 256 x i1> %v) {
222222

223223
define zeroext i1 @vreduce_and_nxv512i1(<vscale x 512 x i1> %v) {
224224
; THROUGHPUT-LABEL: 'vreduce_and_nxv512i1'
225-
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> %v)
225+
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> %v)
226226
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i1 %red
227227
;
228228
%red = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> %v)
@@ -231,7 +231,7 @@ define zeroext i1 @vreduce_and_nxv512i1(<vscale x 512 x i1> %v) {
231231

232232
define zeroext i1 @vreduce_and_nxv1024i1(<vscale x 1024 x i1> %v) {
233233
; THROUGHPUT-LABEL: 'vreduce_and_nxv1024i1'
234-
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> %v)
234+
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 17 for instruction: %red = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> %v)
235235
; THROUGHPUT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i1 %red
236236
;
237237
%red = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> %v)

llvm/test/Analysis/CostModel/RISCV/reduce-and.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ define i32 @reduce_i1(i32 %arg) {
2424
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV16 = call i1 @llvm.vector.reduce.and.nxv16i1(<vscale x 16 x i1> undef)
2525
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV32 = call i1 @llvm.vector.reduce.and.nxv32i1(<vscale x 32 x i1> undef)
2626
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV64 = call i1 @llvm.vector.reduce.and.nxv64i1(<vscale x 64 x i1> undef)
27-
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %NXV128 = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> undef)
28-
; CHECK-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %NXV256 = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> undef)
29-
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %NXV512 = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> undef)
30-
; CHECK-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %NXV1024 = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> undef)
27+
; CHECK-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV128 = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> undef)
28+
; CHECK-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %NXV256 = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> undef)
29+
; CHECK-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %NXV512 = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> undef)
30+
; CHECK-NEXT: Cost Model: Found an estimated cost of 17 for instruction: %NXV1024 = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> undef)
3131
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 undef
3232
;
3333
; SIZE-LABEL: 'reduce_i1'
@@ -49,10 +49,10 @@ define i32 @reduce_i1(i32 %arg) {
4949
; SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV16 = call i1 @llvm.vector.reduce.and.nxv16i1(<vscale x 16 x i1> undef)
5050
; SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV32 = call i1 @llvm.vector.reduce.and.nxv32i1(<vscale x 32 x i1> undef)
5151
; SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV64 = call i1 @llvm.vector.reduce.and.nxv64i1(<vscale x 64 x i1> undef)
52-
; SIZE-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %NXV128 = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> undef)
53-
; SIZE-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %NXV256 = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> undef)
54-
; SIZE-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %NXV512 = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> undef)
55-
; SIZE-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %NXV1024 = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> undef)
52+
; SIZE-NEXT: Cost Model: Found an estimated cost of 3 for instruction: %NXV128 = call i1 @llvm.vector.reduce.and.nxv128i1(<vscale x 128 x i1> undef)
53+
; SIZE-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %NXV256 = call i1 @llvm.vector.reduce.and.nxv256i1(<vscale x 256 x i1> undef)
54+
; SIZE-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %NXV512 = call i1 @llvm.vector.reduce.and.nxv512i1(<vscale x 512 x i1> undef)
55+
; SIZE-NEXT: Cost Model: Found an estimated cost of 17 for instruction: %NXV1024 = call i1 @llvm.vector.reduce.and.nxv1024i1(<vscale x 1024 x i1> undef)
5656
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 undef
5757
;
5858
%V1 = call i1 @llvm.vector.reduce.and.v1i1(<1 x i1> undef)

llvm/test/CodeGen/RISCV/rvv/reduce-and-i1.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ define zeroext i1 @vreduce_and_nxv128i1(<vscale x 128 x i1> %v) {
477477
; CHECK-LABEL: vreduce_and_nxv128i1:
478478
; CHECK: # %bb.0:
479479
; CHECK-NEXT: vsetvli a0, zero, e8, m8, ta, ma
480-
; CHECK-NEXT: vmand.mm v8, v0, v8
481-
; CHECK-NEXT: vmnot.m v8, v8
480+
; CHECK-NEXT: vmnand.mm v8, v0, v8
482481
; CHECK-NEXT: vcpop.m a0, v8
483482
; CHECK-NEXT: seqz a0, a0
484483
; CHECK-NEXT: ret
@@ -492,8 +491,7 @@ define zeroext i1 @vreduce_and_nxv256i1(<vscale x 256 x i1> %v) {
492491
; CHECK-NEXT: vsetvli a0, zero, e8, m8, ta, ma
493492
; CHECK-NEXT: vmand.mm v8, v8, v10
494493
; CHECK-NEXT: vmand.mm v9, v0, v9
495-
; CHECK-NEXT: vmand.mm v8, v9, v8
496-
; CHECK-NEXT: vmnot.m v8, v8
494+
; CHECK-NEXT: vmnand.mm v8, v9, v8
497495
; CHECK-NEXT: vcpop.m a0, v8
498496
; CHECK-NEXT: seqz a0, a0
499497
; CHECK-NEXT: ret
@@ -511,8 +509,7 @@ define zeroext i1 @vreduce_and_nxv512i1(<vscale x 512 x i1> %v) {
511509
; CHECK-NEXT: vmand.mm v11, v0, v11
512510
; CHECK-NEXT: vmand.mm v8, v8, v10
513511
; CHECK-NEXT: vmand.mm v9, v11, v9
514-
; CHECK-NEXT: vmand.mm v8, v9, v8
515-
; CHECK-NEXT: vmnot.m v8, v8
512+
; CHECK-NEXT: vmnand.mm v8, v9, v8
516513
; CHECK-NEXT: vcpop.m a0, v8
517514
; CHECK-NEXT: seqz a0, a0
518515
; CHECK-NEXT: ret
@@ -538,8 +535,7 @@ define zeroext i1 @vreduce_and_nxv1024i1(<vscale x 1024 x i1> %v) {
538535
; CHECK-NEXT: vmand.mm v11, v15, v11
539536
; CHECK-NEXT: vmand.mm v8, v8, v10
540537
; CHECK-NEXT: vmand.mm v9, v11, v9
541-
; CHECK-NEXT: vmand.mm v8, v9, v8
542-
; CHECK-NEXT: vmnot.m v8, v8
538+
; CHECK-NEXT: vmnand.mm v8, v9, v8
543539
; CHECK-NEXT: vcpop.m a0, v8
544540
; CHECK-NEXT: seqz a0, a0
545541
; CHECK-NEXT: ret

0 commit comments

Comments
 (0)