From 5ace48ad0f30d234e3f2e25503a4f041138b4952 Mon Sep 17 00:00:00 2001 From: liuhongt Date: Fri, 27 Aug 2021 12:50:13 +0800 Subject: [PATCH] Check the type of mask while generating cond_op in gimple simplication. gcc/ChangeLog: PR middle-end/102080 * internal-fn.c (cond_vectorized_internal_fn_supported_p): New functions. * internal-fn.h (cond_vectorized_internal_fn_supported_p): New declaration. * match.pd: Check the type of mask while generating cond_op in gimple simplication. gcc/testsuite/ChangeLog: PR middle-end/102080 * gcc.target/i386/pr102080.c: New test. --- gcc/internal-fn.c | 20 ++++++++++++++++++++ gcc/internal-fn.h | 1 + gcc/match.pd | 24 ++++++++++++++++-------- gcc/testsuite/gcc.target/i386/pr102080.c | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr102080.c diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 1360a00f0b9..7f643f545d9 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -4102,6 +4102,26 @@ expand_internal_call (gcall *stmt) expand_internal_call (gimple_call_internal_fn (stmt), stmt); } +/* Check cond_op for vector modes since vectorized_internal_fn_supported_p + doesn't check if mask type matches. */ +bool +cond_vectorized_internal_fn_supported_p (internal_fn ifn, tree type, + tree mask_type) +{ + if (!vectorized_internal_fn_supported_p (ifn, type)) + return false; + + machine_mode mask_mode; + machine_mode vmode = TYPE_MODE (type); + int size1, size2; + if (VECTOR_MODE_P (vmode) + && targetm.vectorize.get_mask_mode (vmode).exists(&mask_mode) + && mask_mode != TYPE_MODE (mask_type)) + return false; + + return true; +} + /* If TYPE is a vector type, return true if IFN is a direct internal function that is supported for that type. If TYPE is a scalar type, return true if IFN is a direct internal function that is supported for diff --git a/gcc/internal-fn.h b/gcc/internal-fn.h index 19d0f849a5a..f0aea00103c 100644 --- a/gcc/internal-fn.h +++ b/gcc/internal-fn.h @@ -236,5 +236,6 @@ extern void expand_PHI (internal_fn, gcall *); extern void expand_SHUFFLEVECTOR (internal_fn, gcall *); extern bool vectorized_internal_fn_supported_p (internal_fn, tree); +extern bool cond_vectorized_internal_fn_supported_p (internal_fn, tree, tree); #endif diff --git a/gcc/match.pd b/gcc/match.pd index f421c74b62c..ded68ec6c71 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6986,14 +6986,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) cond_op (COND_BINARY) (simplify (vec_cond @0 (view_convert? (uncond_op@4 @1 @2)) @3) - (with { tree op_type = TREE_TYPE (@4); } - (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) + (with { tree op_type = TREE_TYPE (@4); + tree mask_type = TREE_TYPE (@0); } + (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op), + op_type, mask_type) && element_precision (type) == element_precision (op_type)) (view_convert (cond_op @0 @1 @2 (view_convert:op_type @3)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@4 @2 @3))) - (with { tree op_type = TREE_TYPE (@4); } - (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) + (with { tree op_type = TREE_TYPE (@4); + tree mask_type = TREE_TYPE (@0); } + (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op), + op_type, mask_type) && element_precision (type) == element_precision (op_type)) (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1))))))) @@ -7002,14 +7006,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) cond_op (COND_TERNARY) (simplify (vec_cond @0 (view_convert? (uncond_op@5 @1 @2 @3)) @4) - (with { tree op_type = TREE_TYPE (@5); } - (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) + (with { tree op_type = TREE_TYPE (@5); + tree mask_type = TREE_TYPE (@0); } + (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op), + op_type, mask_type) && element_precision (type) == element_precision (op_type)) (view_convert (cond_op @0 @1 @2 @3 (view_convert:op_type @4)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@5 @2 @3 @4))) - (with { tree op_type = TREE_TYPE (@5); } - (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) + (with { tree op_type = TREE_TYPE (@5); + tree mask_type = TREE_TYPE (@0); } + (if (cond_vectorized_internal_fn_supported_p (as_internal_fn (cond_op), + op_type, mask_type) && element_precision (type) == element_precision (op_type)) (view_convert (cond_op (bit_not @0) @2 @3 @4 (view_convert:op_type @1))))))) diff --git a/gcc/testsuite/gcc.target/i386/pr102080.c b/gcc/testsuite/gcc.target/i386/pr102080.c new file mode 100644 index 00000000000..4c5ee32ee63 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr102080.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include +typedef float __m256 __attribute__((__vector_size__(32))); +__m256 _mm256_blendv_ps___Y, _mm256_blendv_ps___M, _mm256_mul_ps___A, + _mm256_mul_ps___B, IfThenElse___trans_tmp_9; + +void +__attribute__ ((target("avx"))) +IfThenElse (__m256 no) { + IfThenElse___trans_tmp_9 = _mm256_blendv_ps (no, _mm256_blendv_ps___Y, _mm256_blendv_ps___M); +} +void +__attribute__ ((target("avx512vl"))) +EncodedFromDisplay() { + __m256 __trans_tmp_11 = _mm256_mul_ps___A * _mm256_mul_ps___B; + IfThenElse(__trans_tmp_11); +} -- 2.18.1