[CostModel][X86] Add VPOPCNT/BITALG test coverage for ctpop/cttz costs

This commit is contained in:
Simon Pilgrim 2021-08-19 13:49:50 +01:00
parent b10e74389e
commit 2d60fdd7aa
2 changed files with 103 additions and 2 deletions

View File

@ -2,10 +2,12 @@
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=-popcnt,+sse2 | FileCheck %s -check-prefixes=SSE2,NOPOPCNT
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+sse2 | FileCheck %s -check-prefixes=SSE2,POPCNT
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+sse4.2 | FileCheck %s -check-prefixes=POPCNT,SSE42
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx | FileCheck %s -check-prefixes=POPCNT,AVX1
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx2 | FileCheck %s -check-prefixes=POPCNT,AVX2
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx | FileCheck %s -check-prefixes=POPCNT,AVX,AVX1
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx2 | FileCheck %s -check-prefixes=POPCNT,AVX,AVX2
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx512f | FileCheck %s -check-prefixes=POPCNT,AVX512,AVX512F
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx512vl,+avx512bw,+avx512dq | FileCheck %s -check-prefixes=POPCNT,AVX512,AVX512BW
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx512vl,+avx512vpopcntdq | FileCheck %s -check-prefixes=POPCNT,AVX512,AVX512VPOPCNT
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+popcnt,+avx512vl,+avx512bitalg | FileCheck %s -check-prefixes=POPCNT,AVX512,AVX512BITALG
; Verify the cost of scalar population count instructions.
@ -153,6 +155,14 @@ define <8 x i64> @var_ctpop_v8i64(<8 x i64> %a) {
; AVX512BW-LABEL: 'var_ctpop_v8i64'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %ctpop = call <8 x i64> @llvm.ctpop.v8i64(<8 x i64> %a)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %ctpop
;
; AVX512VPOPCNT-LABEL: 'var_ctpop_v8i64'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 16 for instruction: %ctpop = call <8 x i64> @llvm.ctpop.v8i64(<8 x i64> %a)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %ctpop
;
; AVX512BITALG-LABEL: 'var_ctpop_v8i64'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 7 for instruction: %ctpop = call <8 x i64> @llvm.ctpop.v8i64(<8 x i64> %a)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %ctpop
;
%ctpop = call <8 x i64> @llvm.ctpop.v8i64(<8 x i64> %a)
ret <8 x i64> %ctpop
@ -228,6 +238,14 @@ define <16 x i32> @var_ctpop_v16i32(<16 x i32> %a) {
; AVX512BW-LABEL: 'var_ctpop_v16i32'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %ctpop = call <16 x i32> @llvm.ctpop.v16i32(<16 x i32> %a)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %ctpop
;
; AVX512VPOPCNT-LABEL: 'var_ctpop_v16i32'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %ctpop = call <16 x i32> @llvm.ctpop.v16i32(<16 x i32> %a)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %ctpop
;
; AVX512BITALG-LABEL: 'var_ctpop_v16i32'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 11 for instruction: %ctpop = call <16 x i32> @llvm.ctpop.v16i32(<16 x i32> %a)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %ctpop
;
%ctpop = call <16 x i32> @llvm.ctpop.v16i32(<16 x i32> %a)
ret <16 x i32> %ctpop
@ -303,6 +321,14 @@ define <32 x i16> @var_ctpop_v32i16(<32 x i16> %a) {
; AVX512BW-LABEL: 'var_ctpop_v32i16'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %ctpop = call <32 x i16> @llvm.ctpop.v32i16(<32 x i16> %a)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %ctpop
;
; AVX512VPOPCNT-LABEL: 'var_ctpop_v32i16'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %ctpop = call <32 x i16> @llvm.ctpop.v32i16(<32 x i16> %a)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %ctpop
;
; AVX512BITALG-LABEL: 'var_ctpop_v32i16'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %ctpop = call <32 x i16> @llvm.ctpop.v32i16(<32 x i16> %a)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %ctpop
;
%ctpop = call <32 x i16> @llvm.ctpop.v32i16(<32 x i16> %a)
ret <32 x i16> %ctpop
@ -378,6 +404,14 @@ define <64 x i8> @var_ctpop_v64i8(<64 x i8> %a) {
; AVX512BW-LABEL: 'var_ctpop_v64i8'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %ctpop = call <64 x i8> @llvm.ctpop.v64i8(<64 x i8> %a)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %ctpop
;
; AVX512VPOPCNT-LABEL: 'var_ctpop_v64i8'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %ctpop = call <64 x i8> @llvm.ctpop.v64i8(<64 x i8> %a)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %ctpop
;
; AVX512BITALG-LABEL: 'var_ctpop_v64i8'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %ctpop = call <64 x i8> @llvm.ctpop.v64i8(<64 x i8> %a)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %ctpop
;
%ctpop = call <64 x i8> @llvm.ctpop.v64i8(<64 x i8> %a)
ret <64 x i8> %ctpop

View File

@ -6,6 +6,9 @@
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx2 | FileCheck %s -check-prefixes=BMI,AVX,AVX2
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx512f | FileCheck %s -check-prefixes=BMI,AVX512,AVX512F
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx512vl,+avx512bw,+avx512dq | FileCheck %s -check-prefixes=BMI,AVX512,AVX512BW
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx512vl,+avx512bw,+avx512dq | FileCheck %s -check-prefixes=BMI,AVX512,AVX512BW
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx512vl,+avx512vpopcntdq | FileCheck %s -check-prefixes=BMI,AVX512,AVX512VPOPCNT
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -cost-model -analyze -mattr=+bmi,+avx512vl,+avx512bitalg | FileCheck %s -check-prefixes=BMI,AVX512,AVX512BITALG
; Verify the cost of scalar trailing zero count instructions.
@ -251,6 +254,14 @@ define <8 x i64> @var_cttz_v8i64(<8 x i64> %a) {
; AVX512BW-LABEL: 'var_cttz_v8i64'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 false)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v8i64'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 20 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 false)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v8i64'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 false)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
%cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 0)
ret <8 x i64> %cttz
@ -280,6 +291,14 @@ define <8 x i64> @var_cttz_v8i64u(<8 x i64> %a) {
; AVX512BW-LABEL: 'var_cttz_v8i64u'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 true)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v8i64u'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 20 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 true)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v8i64u'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 10 for instruction: %cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 true)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <8 x i64> %cttz
;
%cttz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %a, i1 1)
ret <8 x i64> %cttz
@ -401,6 +420,14 @@ define <16 x i32> @var_cttz_v16i32(<16 x i32> %a) {
; AVX512BW-LABEL: 'var_cttz_v16i32'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 false)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v16i32'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 false)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v16i32'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 false)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
%cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 0)
ret <16 x i32> %cttz
@ -430,6 +457,14 @@ define <16 x i32> @var_cttz_v16i32u(<16 x i32> %a) {
; AVX512BW-LABEL: 'var_cttz_v16i32u'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 true)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v16i32u'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 true)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v16i32u'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 14 for instruction: %cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 true)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <16 x i32> %cttz
;
%cttz = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %a, i1 1)
ret <16 x i32> %cttz
@ -551,6 +586,14 @@ define <32 x i16> @var_cttz_v32i16(<32 x i16> %a) {
; AVX512BW-LABEL: 'var_cttz_v32i16'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 false)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v32i16'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 false)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v32i16'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 false)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
%cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 0)
ret <32 x i16> %cttz
@ -580,6 +623,14 @@ define <32 x i16> @var_cttz_v32i16u(<32 x i16> %a) {
; AVX512BW-LABEL: 'var_cttz_v32i16u'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 true)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v32i16u'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 24 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 true)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v32i16u'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 12 for instruction: %cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 true)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <32 x i16> %cttz
;
%cttz = call <32 x i16> @llvm.cttz.v32i16(<32 x i16> %a, i1 1)
ret <32 x i16> %cttz
@ -701,6 +752,14 @@ define <64 x i8> @var_cttz_v64i8(<64 x i8> %a) {
; AVX512BW-LABEL: 'var_cttz_v64i8'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 false)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v64i8'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 false)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v64i8'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 false)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
%cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 0)
ret <64 x i8> %cttz
@ -730,6 +789,14 @@ define <64 x i8> @var_cttz_v64i8u(<64 x i8> %a) {
; AVX512BW-LABEL: 'var_cttz_v64i8u'
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 true)
; AVX512BW-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
; AVX512VPOPCNT-LABEL: 'var_cttz_v64i8u'
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 18 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 true)
; AVX512VPOPCNT-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
; AVX512BITALG-LABEL: 'var_cttz_v64i8u'
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 9 for instruction: %cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 true)
; AVX512BITALG-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret <64 x i8> %cttz
;
%cttz = call <64 x i8> @llvm.cttz.v64i8(<64 x i8> %a, i1 1)
ret <64 x i8> %cttz