Skip to content

Commit 74460bc

Browse files
committed
[RISCV][CostModel] Remove inst cost of cmp inst in cmp-select sequence.
Cmp and select instructinos will lower to SELECT_CC and lower to PseudoCCMOVGPR which will generate a conditional branch inst and a move inst. The cost of (cmp + select) = (0 + select inst cost).
1 parent c82986f commit 74460bc

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,13 @@ InstructionCost RISCVTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
14361436
}
14371437
}
14381438

1439+
// The cmp + select instructions will lower to SELECT_CC and lower to
1440+
// PseudoCCMOVGPR which will generate a conditional branch + mv. The
1441+
// cost of (cmp + select) will be (0 + select inst cost).
1442+
if (I && isa<CmpInst>(I) && I->hasOneUser() &&
1443+
isa<SelectInst>(I->user_back()) && I->user_back()->getOperand(0) == I)
1444+
return 0;
1445+
14391446
// TODO: Add cost for scalar type.
14401447

14411448
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind, I);

llvm/test/Analysis/CostModel/RISCV/cmp-select.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
; RUN: opt < %s -mtriple=riscv64 -passes="print<cost-model>" -cost-kind=throughput 2>&1 -disable-output | FileCheck %s --check-prefixes=CHECK
33

44
define void @cmp-select() {
5+
;
56
; CHECK-LABEL: 'cmp-select'
6-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %cmp1 = icmp slt i64 0, 1
7+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %cmp1 = icmp slt i64 0, 1
78
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %select1 = select i1 %cmp1, i32 5, i32 4
89
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
910
;

llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ define void @double_stride_ptr_iv(ptr %p, ptr %p2, i64 %stride) {
699699
; STRIDED-NEXT: entry:
700700
; STRIDED-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
701701
; STRIDED-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
702-
; STRIDED-NEXT: [[TMP2:%.*]] = call i64 @llvm.umax.i64(i64 32, i64 [[TMP1]])
702+
; STRIDED-NEXT: [[TMP2:%.*]] = call i64 @llvm.umax.i64(i64 24, i64 [[TMP1]])
703703
; STRIDED-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP2]]
704704
; STRIDED-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
705705
; STRIDED: vector.memcheck:

0 commit comments

Comments
 (0)