[llvm] bd0109f - [CostModel][X86] Move AVX512/AVX2 uniform shift costs into the generic uniform cost tables
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 04:19:44 PDT 2022
Author: Simon Pilgrim
Date: 2022-09-12T12:08:42+01:00
New Revision: bd0109f39243e12f494e53bc99e95d76a1585ef8
URL: https://github.com/llvm/llvm-project/commit/bd0109f39243e12f494e53bc99e95d76a1585ef8
DIFF: https://github.com/llvm/llvm-project/commit/bd0109f39243e12f494e53bc99e95d76a1585ef8.diff
LOG: [CostModel][X86] Move AVX512/AVX2 uniform shift costs into the generic uniform cost tables
They shouldn't be happening after XOP shift costs - AVX2 shift supports takes preference over XOP for everything but vXi8 shifts - the improvement is pretty limited as it only affects bdver4 targets but it does help clean up a fraction of the messy shift cost logic....
Added:
Modified:
llvm/lib/Target/X86/X86TargetTransformInfo.cpp
llvm/test/Analysis/CostModel/X86/vshift-ashr-cost-inseltpoison.ll
llvm/test/Analysis/CostModel/X86/vshift-ashr-cost.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index b66126a322d12..373be67d5b4ed 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -559,6 +559,18 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
if (auto KindCost = Entry->Cost[CostKind])
return LT.first * KindCost.value();
+ static const CostKindTblEntry AVX512UniformCostTable[] = {
+ { ISD::SRA, MVT::v2i64, { 1 } },
+ { ISD::SRA, MVT::v4i64, { 1 } },
+ { ISD::SRA, MVT::v8i64, { 1 } },
+ };
+
+ if (ST->hasAVX512() && Op2Info.isUniform())
+ if (const auto *Entry =
+ CostTableLookup(AVX512UniformCostTable, ISD, LT.second))
+ if (auto KindCost = Entry->Cost[CostKind])
+ return LT.first * KindCost.value();
+
static const CostKindTblEntry AVX2UniformCostTable[] = {
// Uniform splats are cheaper for the following instructions.
{ ISD::SHL, MVT::v16i16, { 1 } }, // psllw.
@@ -573,6 +585,7 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
{ ISD::SRA, MVT::v8i32, { 1 } }, // psrad
{ ISD::SHL, MVT::v4i64, { 1 } }, // psllq
{ ISD::SRL, MVT::v4i64, { 1 } }, // psrlq
+ { ISD::SRA, MVT::v4i64, { 4 } }, // 2*psrad + shuffle.
};
if (ST->hasAVX2() && Op2Info.isUniform())
@@ -823,16 +836,6 @@ InstructionCost X86TTIImpl::getArithmeticInstrCost(
return LT.first * KindCost.value();
}
- static const CostKindTblEntry AVX2UniformShiftCostTable[] = {
- { ISD::SRA, MVT::v4i64, { 4 } }, // 2*psrad + shuffle.
- };
-
- if (ST->hasAVX2() && Op2Info.isUniform())
- if (const auto *Entry =
- CostTableLookup(AVX2UniformShiftCostTable, ISD, LT.second))
- if (auto KindCost = Entry->Cost[CostKind])
- return LT.first * KindCost.value();
-
static const CostKindTblEntry SSE2UniformShiftCostTable[] = {
// Uniform splats are cheaper for the following instructions.
{ ISD::SHL, MVT::v16i16, { 2+2 } }, // 2*psllw + split.
diff --git a/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost-inseltpoison.ll b/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost-inseltpoison.ll
index 8c7246bffb694..497896700b83e 100644
--- a/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost-inseltpoison.ll
+++ b/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost-inseltpoison.ll
@@ -549,7 +549,7 @@ define <4 x i64> @splatvar_shift_v4i64(<4 x i64> %a, i64 %b) {
; XOPAVX2-LABEL: 'splatvar_shift_v4i64'
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert = insertelement <4 x i64> poison, i64 %b, i32 0
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %splat = shufflevector <4 x i64> %insert, <4 x i64> poison, <4 x i32> zeroinitializer
-; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %shift = ashr <4 x i64> %a, %splat
+; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %shift = ashr <4 x i64> %a, %splat
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %shift
;
; AVX512-LABEL: 'splatvar_shift_v4i64'
@@ -604,7 +604,7 @@ define <8 x i64> @splatvar_shift_v8i64(<8 x i64> %a, i64 %b) {
; XOPAVX2-LABEL: 'splatvar_shift_v8i64'
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert = insertelement <8 x i64> poison, i64 %b, i32 0
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %splat = shufflevector <8 x i64> %insert, <8 x i64> poison, <8 x i32> zeroinitializer
-; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %shift = ashr <8 x i64> %a, %splat
+; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %shift = ashr <8 x i64> %a, %splat
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %shift
;
; AVX512-LABEL: 'splatvar_shift_v8i64'
diff --git a/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost.ll b/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost.ll
index 3a01a6e2e999a..e5b9dd14e5a7a 100644
--- a/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost.ll
+++ b/llvm/test/Analysis/CostModel/X86/vshift-ashr-cost.ll
@@ -549,7 +549,7 @@ define <4 x i64> @splatvar_shift_v4i64(<4 x i64> %a, i64 %b) {
; XOPAVX2-LABEL: 'splatvar_shift_v4i64'
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert = insertelement <4 x i64> undef, i64 %b, i32 0
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %splat = shufflevector <4 x i64> %insert, <4 x i64> undef, <4 x i32> zeroinitializer
-; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %shift = ashr <4 x i64> %a, %splat
+; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 4 for instruction: %shift = ashr <4 x i64> %a, %splat
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <4 x i64> %shift
;
; AVX512-LABEL: 'splatvar_shift_v4i64'
@@ -604,7 +604,7 @@ define <8 x i64> @splatvar_shift_v8i64(<8 x i64> %a, i64 %b) {
; XOPAVX2-LABEL: 'splatvar_shift_v8i64'
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert = insertelement <8 x i64> undef, i64 %b, i32 0
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %splat = shufflevector <8 x i64> %insert, <8 x i64> undef, <8 x i32> zeroinitializer
-; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %shift = ashr <8 x i64> %a, %splat
+; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %shift = ashr <8 x i64> %a, %splat
; XOPAVX2-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %shift
;
; AVX512-LABEL: 'splatvar_shift_v8i64'
More information about the llvm-commits
mailing list