Skip to content

Commit b688c91

Browse files
committed
TTI: Check legalization cost of min/max ISD nodes
Instead of counting the cost of the assumed expansion. The AMDGPU costs for the i64 case look too high to me.
1 parent 879d467 commit b688c91

File tree

10 files changed

+426
-484
lines changed

10 files changed

+426
-484
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,21 +2131,17 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
21312131
return Cost;
21322132
}
21332133
case Intrinsic::smax:
2134+
ISD = ISD::SMAX;
2135+
break;
21342136
case Intrinsic::smin:
2137+
ISD = ISD::SMIN;
2138+
break;
21352139
case Intrinsic::umax:
2136-
case Intrinsic::umin: {
2137-
// minmax(X,Y) = select(icmp(X,Y),X,Y)
2138-
Type *CondTy = RetTy->getWithNewBitWidth(1);
2139-
bool IsUnsigned = IID == Intrinsic::umax || IID == Intrinsic::umin;
2140-
CmpInst::Predicate Pred =
2141-
IsUnsigned ? CmpInst::ICMP_UGT : CmpInst::ICMP_SGT;
2142-
InstructionCost Cost = 0;
2143-
Cost += thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy,
2144-
Pred, CostKind);
2145-
Cost += thisT()->getCmpSelInstrCost(BinaryOperator::Select, RetTy, CondTy,
2146-
Pred, CostKind);
2147-
return Cost;
2148-
}
2140+
ISD = ISD::UMAX;
2141+
break;
2142+
case Intrinsic::umin:
2143+
ISD = ISD::UMIN;
2144+
break;
21492145
case Intrinsic::sadd_sat:
21502146
ISD = ISD::SADDSAT;
21512147
break;

llvm/test/Analysis/CostModel/AArch64/min-max.ll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
66

77
define void @umin() {
88
; CHECK-LABEL: 'umin'
9-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i8 = call i8 @llvm.umin.i8(i8 undef, i8 undef)
10-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i16 = call i16 @llvm.umin.i16(i16 undef, i16 undef)
11-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i32 = call i32 @llvm.umin.i32(i32 undef, i32 undef)
12-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i64 = call i64 @llvm.umin.i64(i64 undef, i64 undef)
9+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i8 = call i8 @llvm.umin.i8(i8 undef, i8 undef)
10+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i16 = call i16 @llvm.umin.i16(i16 undef, i16 undef)
11+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i32 = call i32 @llvm.umin.i32(i32 undef, i32 undef)
12+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i64 = call i64 @llvm.umin.i64(i64 undef, i64 undef)
1313
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1i8 = call <1 x i8> @llvm.umin.v1i8(<1 x i8> undef, <1 x i8> undef)
1414
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V3i8 = call <3 x i8> @llvm.umin.v3i8(<3 x i8> undef, <3 x i8> undef)
1515
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4i8 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> undef, <4 x i8> undef)
@@ -53,10 +53,10 @@ define void @umin() {
5353

5454
define void @umax() {
5555
; CHECK-LABEL: 'umax'
56-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i8 = call i8 @llvm.umax.i8(i8 undef, i8 undef)
57-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i16 = call i16 @llvm.umax.i16(i16 undef, i16 undef)
58-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i32 = call i32 @llvm.umax.i32(i32 undef, i32 undef)
59-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i64 = call i64 @llvm.umax.i64(i64 undef, i64 undef)
56+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i8 = call i8 @llvm.umax.i8(i8 undef, i8 undef)
57+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i16 = call i16 @llvm.umax.i16(i16 undef, i16 undef)
58+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i32 = call i32 @llvm.umax.i32(i32 undef, i32 undef)
59+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i64 = call i64 @llvm.umax.i64(i64 undef, i64 undef)
6060
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1i8 = call <1 x i8> @llvm.umax.v1i8(<1 x i8> undef, <1 x i8> undef)
6161
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V3i8 = call <3 x i8> @llvm.umax.v3i8(<3 x i8> undef, <3 x i8> undef)
6262
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4i8 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> undef, <4 x i8> undef)
@@ -100,10 +100,10 @@ define void @umax() {
100100

101101
define void @smin() {
102102
; CHECK-LABEL: 'smin'
103-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i8 = call i8 @llvm.smin.i8(i8 undef, i8 undef)
104-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i16 = call i16 @llvm.smin.i16(i16 undef, i16 undef)
105-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i32 = call i32 @llvm.smin.i32(i32 undef, i32 undef)
106-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i64 = call i64 @llvm.smin.i64(i64 undef, i64 undef)
103+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i8 = call i8 @llvm.smin.i8(i8 undef, i8 undef)
104+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i16 = call i16 @llvm.smin.i16(i16 undef, i16 undef)
105+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i32 = call i32 @llvm.smin.i32(i32 undef, i32 undef)
106+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i64 = call i64 @llvm.smin.i64(i64 undef, i64 undef)
107107
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1i8 = call <1 x i8> @llvm.smin.v1i8(<1 x i8> undef, <1 x i8> undef)
108108
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V3i8 = call <3 x i8> @llvm.smin.v3i8(<3 x i8> undef, <3 x i8> undef)
109109
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4i8 = call <4 x i8> @llvm.smin.v4i8(<4 x i8> undef, <4 x i8> undef)
@@ -147,10 +147,10 @@ define void @smin() {
147147

148148
define void @smax() {
149149
; CHECK-LABEL: 'smax'
150-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i8 = call i8 @llvm.smax.i8(i8 undef, i8 undef)
151-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i16 = call i16 @llvm.smax.i16(i16 undef, i16 undef)
152-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i32 = call i32 @llvm.smax.i32(i32 undef, i32 undef)
153-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %i64 = call i64 @llvm.smax.i64(i64 undef, i64 undef)
150+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i8 = call i8 @llvm.smax.i8(i8 undef, i8 undef)
151+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i16 = call i16 @llvm.smax.i16(i16 undef, i16 undef)
152+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i32 = call i32 @llvm.smax.i32(i32 undef, i32 undef)
153+
; CHECK-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %i64 = call i64 @llvm.smax.i64(i64 undef, i64 undef)
154154
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V1i8 = call <1 x i8> @llvm.smax.v1i8(<1 x i8> undef, <1 x i8> undef)
155155
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V3i8 = call <3 x i8> @llvm.smax.v3i8(<3 x i8> undef, <3 x i8> undef)
156156
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4i8 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> undef, <4 x i8> undef)

0 commit comments

Comments
 (0)