Skip to content

Commit 86b7ce9

Browse files
authored
[CostModel] Remove some negative costs. (llvm#135533)
The cost model in the past returned -1 for unknown costs, but over time this has largely been removed. This cleans up some of the uses that have remained. It uses 0/free for the cost of an insert and 1/basic for the cost of anything that is unknown.
1 parent 82a1d50 commit 86b7ce9

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,11 @@ class TargetTransformInfoImplBase {
813813
getInsertExtractValueCost(unsigned Opcode,
814814
TTI::TargetCostKind CostKind) const {
815815
// Note: The `insertvalue` cost here is chosen to match the default case of
816-
// getInstructionCost() -- as pior to adding this helper `insertvalue` was
816+
// getInstructionCost() -- as prior to adding this helper `insertvalue` was
817817
// not handled.
818-
if (Opcode == Instruction::InsertValue)
819-
return CostKind == TTI::TCK_RecipThroughput ? -1 : TTI::TCC_Basic;
818+
if (Opcode == Instruction::InsertValue &&
819+
CostKind != TTI::TCK_RecipThroughput)
820+
return TTI::TCC_Basic;
820821
return TTI::TCC_Free;
821822
}
822823

@@ -1651,9 +1652,8 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
16511652
}
16521653
}
16531654

1654-
// By default, just classify everything as 'basic' or -1 to represent that
1655-
// don't know the throughput cost.
1656-
return CostKind == TTI::TCK_RecipThroughput ? -1 : TTI::TCC_Basic;
1655+
// By default, just classify everything remaining as 'basic'.
1656+
return TTI::TCC_Basic;
16571657
}
16581658

16591659
bool isExpensiveToSpeculativelyExecute(const Instruction *I) const override {

llvm/test/Analysis/CostModel/RISCV/shuffle-interleave.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ define {<4 x i8>, <4 x i8>} @deinterleave_2(<8 x i8> %v) {
5858
; CHECK-LABEL: 'deinterleave_2'
5959
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %v0 = shufflevector <8 x i8> %v, <8 x i8> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
6060
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %v1 = shufflevector <8 x i8> %v, <8 x i8> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
61-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res0 = insertvalue { <4 x i8>, <4 x i8> } poison, <4 x i8> %v0, 0
62-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res1 = insertvalue { <4 x i8>, <4 x i8> } %res0, <4 x i8> %v1, 1
61+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res0 = insertvalue { <4 x i8>, <4 x i8> } poison, <4 x i8> %v0, 0
62+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res1 = insertvalue { <4 x i8>, <4 x i8> } %res0, <4 x i8> %v1, 1
6363
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { <4 x i8>, <4 x i8> } %res1
6464
;
6565
%v0 = shufflevector <8 x i8> %v, <8 x i8> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
@@ -73,8 +73,8 @@ define {<4 x i32>, <4 x i32>} @deinterleave_2_m1_dest(<8 x i32> %v) {
7373
; CHECK-LABEL: 'deinterleave_2_m1_dest'
7474
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v0 = shufflevector <8 x i32> %v, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
7575
; CHECK-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v1 = shufflevector <8 x i32> %v, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
76-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res0 = insertvalue { <4 x i32>, <4 x i32> } poison, <4 x i32> %v0, 0
77-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res1 = insertvalue { <4 x i32>, <4 x i32> } %res0, <4 x i32> %v1, 1
76+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res0 = insertvalue { <4 x i32>, <4 x i32> } poison, <4 x i32> %v0, 0
77+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res1 = insertvalue { <4 x i32>, <4 x i32> } %res0, <4 x i32> %v1, 1
7878
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { <4 x i32>, <4 x i32> } %res1
7979
;
8080
%v0 = shufflevector <8 x i32> %v, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
@@ -88,8 +88,8 @@ define {<8 x i32>, <8 x i32>} @deinterleave_2_m2_dest(<16 x i32> %v) {
8888
; CHECK-LABEL: 'deinterleave_2_m2_dest'
8989
; CHECK-NEXT: Cost Model: Found an estimated cost of 22 for instruction: %v0 = shufflevector <16 x i32> %v, <16 x i32> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
9090
; CHECK-NEXT: Cost Model: Found an estimated cost of 22 for instruction: %v1 = shufflevector <16 x i32> %v, <16 x i32> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
91-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res0 = insertvalue { <8 x i32>, <8 x i32> } poison, <8 x i32> %v0, 0
92-
; CHECK-NEXT: Cost Model: Found an estimated cost of -1 for instruction: %res1 = insertvalue { <8 x i32>, <8 x i32> } %res0, <8 x i32> %v1, 1
91+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res0 = insertvalue { <8 x i32>, <8 x i32> } poison, <8 x i32> %v0, 0
92+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %res1 = insertvalue { <8 x i32>, <8 x i32> } %res0, <8 x i32> %v1, 1
9393
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret { <8 x i32>, <8 x i32> } %res1
9494
;
9595
%v0 = shufflevector <16 x i32> %v, <16 x i32> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>

0 commit comments

Comments
 (0)