This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix one testcase from PR61194
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 May 2014 13:15:45 +0200 (CEST)
- Subject: [PATCH] Fix one testcase from PR61194
- Authentication-results: sourceware.org; auth=none
This fixes the non-regression testcase from PR61194 by also
recognizing COND_EXPRs as sink for bool expressions in vectorizer
pattern detection.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2014-05-16 Richard Biener <rguenther@suse.de>
PR tree-optimization/61194
* tree-vect-patterns.c (adjust_bool_pattern): Also handle
bool patterns ending in a COND_EXPR.
* gcc.dg/vect/pr61194.c: New testcase.
Index: gcc/tree-vect-patterns.c
===================================================================
*** gcc/tree-vect-patterns.c (revision 210492)
--- gcc/tree-vect-patterns.c (working copy)
*************** adjust_bool_pattern (tree var, tree out_
*** 2889,2895 ****
S5 e_b = c_b | d_b;
S6 f_T = (TYPE) e_b;
! where type 'TYPE' is an integral type.
Input:
--- 2889,2900 ----
S5 e_b = c_b | d_b;
S6 f_T = (TYPE) e_b;
! where type 'TYPE' is an integral type. Or a similar pattern
! ending in
!
! S6 f_Y = e_b ? r_Y : s_Y;
!
! as results from if-conversion of a complex condition.
Input:
*************** vect_recog_bool_pattern (vec<gimple> *st
*** 2966,2971 ****
--- 2971,3015 ----
*type_out = vectype;
*type_in = vectype;
stmts->safe_push (last_stmt);
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "vect_recog_bool_pattern: detected:\n");
+
+ return pattern_stmt;
+ }
+ else if (rhs_code == COND_EXPR
+ && TREE_CODE (var) == SSA_NAME)
+ {
+ vectype = get_vectype_for_scalar_type (TREE_TYPE (lhs));
+ if (vectype == NULL_TREE)
+ return NULL;
+
+ /* Build a scalar type for the boolean result that when
+ vectorized matches the vector type of the result in
+ size and number of elements. */
+ unsigned prec
+ = wi::udiv_trunc (TYPE_SIZE (vectype),
+ TYPE_VECTOR_SUBPARTS (vectype)).to_uhwi ();
+ tree type
+ = build_nonstandard_integer_type (prec,
+ TYPE_UNSIGNED (TREE_TYPE (var)));
+ if (get_vectype_for_scalar_type (type) == NULL_TREE)
+ return NULL;
+
+ if (!check_bool_pattern (var, loop_vinfo, bb_vinfo))
+ return NULL;
+
+ rhs = adjust_bool_pattern (var, type, NULL_TREE, stmts);
+ lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
+ pattern_stmt
+ = gimple_build_assign_with_ops (COND_EXPR, lhs,
+ build2 (NE_EXPR, boolean_type_node,
+ rhs, build_int_cst (type, 0)),
+ gimple_assign_rhs2 (last_stmt),
+ gimple_assign_rhs3 (last_stmt));
+ *type_out = vectype;
+ *type_in = vectype;
+ stmts->safe_push (last_stmt);
if (dump_enabled_p ())
dump_printf_loc (MSG_NOTE, vect_location,
"vect_recog_bool_pattern: detected:\n");
Index: gcc/testsuite/gcc.dg/vect/pr61194.c
===================================================================
*** gcc/testsuite/gcc.dg/vect/pr61194.c (revision 0)
--- gcc/testsuite/gcc.dg/vect/pr61194.c (working copy)
***************
*** 0 ****
--- 1,43 ----
+ /* { dg-require-effective-target vect_cond_mixed } */
+ /* { dg-additional-options "-ftree-loop-if-convert-stores" } */
+
+ #include "tree-vect.h"
+
+ static float x[1024];
+ static float y[1024];
+ static float z[1024];
+ static float w[1024];
+
+ void __attribute__((noinline,noclone)) barX()
+ {
+ int i;
+ for (i=0; i<1024; ++i)
+ z[i] = ((x[i]>0) & (w[i]<0)) ? z[i] : y[i];
+ }
+
+ int main()
+ {
+ int i;
+
+ check_vect ();
+
+ for (i = 0; i < 1024; ++i)
+ {
+ x[i] = -10 + i;
+ w[i] = 100 - i;
+ z[i] = 0.;
+ y[i] = 1.;
+ __asm__ volatile ("" : : : "memory");
+ }
+
+ barX();
+
+ for (i = 0; i < 1024; ++i)
+ if (z[i] != ((x[i]>0 && w[i]<0) ? 0. : 1.))
+ abort ();
+
+ return 0;
+ }
+
+ /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
+ /* { dg-final { cleanup-tree-dump "vect" } } */