Check mask type when doing cond_op related gimple simplification.
authorliuhongt <hongtao.liu@intel.com>
Thu, 2 Sep 2021 05:05:54 +0000 (13:05 +0800)
committerliuhongt <hongtao.liu@intel.com>
Thu, 16 Sep 2021 08:35:29 +0000 (16:35 +0800)
gcc/ChangeLog:

PR middle-end/102080
* match.pd: Check mask type when doing cond_op related gimple
simplification.
* tree.c (is_truth_type_for): New function.
* tree.h (is_truth_type_for): New declaration.

gcc/testsuite/ChangeLog:

PR middle-end/102080
* gcc.target/i386/pr102080.c: New test.

gcc/match.pd
gcc/testsuite/gcc.target/i386/pr102080.c [new file with mode: 0644]
gcc/tree.c
gcc/tree.h

index 008f775..41f9e6d 100644 (file)
@@ -7020,13 +7020,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (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)
-       && element_precision (type) == element_precision (op_type))
+       && is_truth_type_for (op_type, TREE_TYPE (@0)))
     (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)
-       && element_precision (type) == element_precision (op_type))
+       && is_truth_type_for (op_type, TREE_TYPE (@0)))
     (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1)))))))
 
 /* Same for ternary operations.  */
@@ -7036,13 +7036,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (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)
-       && element_precision (type) == element_precision (op_type))
+       && is_truth_type_for (op_type, TREE_TYPE (@0)))
     (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)
-       && element_precision (type) == element_precision (op_type))
+       && is_truth_type_for (op_type, TREE_TYPE (@0)))
     (view_convert (cond_op (bit_not @0) @2 @3 @4
                  (view_convert:op_type @1)))))))
 #endif
diff --git a/gcc/testsuite/gcc.target/i386/pr102080.c b/gcc/testsuite/gcc.target/i386/pr102080.c
new file mode 100644 (file)
index 0000000..4c5ee32
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include<immintrin.h>
+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);
+}
index 3d15948..994775d 100644 (file)
@@ -10737,6 +10737,35 @@ signed_type_for (tree type)
   return signed_or_unsigned_type_for (0, type);
 }
 
+/* - For VECTOR_TYPEs:
+    - The truth type must be a VECTOR_BOOLEAN_TYPE.
+    - The number of elements must match (known_eq).
+    - targetm.vectorize.get_mask_mode exists, and exactly
+      the same mode as the truth type.
+   - Otherwise, the truth type must be a BOOLEAN_TYPE
+     or useless_type_conversion_p to BOOLEAN_TYPE.  */
+bool
+is_truth_type_for (tree type, tree truth_type)
+{
+  machine_mode mask_mode = TYPE_MODE (truth_type);
+  machine_mode vmode = TYPE_MODE (type);
+  machine_mode tmask_mode;
+
+  if (TREE_CODE (type) == VECTOR_TYPE)
+    {
+      if (VECTOR_BOOLEAN_TYPE_P (truth_type)
+         && known_eq (TYPE_VECTOR_SUBPARTS (type),
+                      TYPE_VECTOR_SUBPARTS (truth_type))
+         && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode)
+         && tmask_mode == mask_mode)
+       return true;
+
+      return false;
+    }
+
+  return useless_type_conversion_p (boolean_type_node, truth_type);
+}
+
 /* If TYPE is a vector type, return a signed integer vector type with the
    same width and number of subparts. Otherwise return boolean_type_node.  */
 
index 7274ba7..8477f89 100644 (file)
@@ -4591,6 +4591,7 @@ extern tree build_string_literal (unsigned, const char * = NULL,
 extern tree signed_or_unsigned_type_for (int, tree);
 extern tree signed_type_for (tree);
 extern tree unsigned_type_for (tree);
+extern bool is_truth_type_for (tree, tree);
 extern tree truth_type_for (tree);
 extern tree build_pointer_type_for_mode (tree, machine_mode, bool);
 extern tree build_pointer_type (tree);