From f2d040abea60db10675e0a5c2f91b7991541df90 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Fri, 1 Mar 2019 13:05:40 +0000 Subject: [PATCH] Fix mask type choice in vectorizable_call (PR 89535) This is another case in which we were failing to pass the expected mask vector type to vect_get_vec_def_for_operand. 2019-02-28 Richard Sandiford gcc/ PR tree-optimization/89535 * tree-vect-stmts.c (vectorizable_call): Record the vector types for each operand. Calculate the fallback choice for mask operands and pass it to vect_get_vec_def_for_operand. gcc/testsuite/ PR tree-optimization/89535 * gfortran.dg/vect/pr89535.f90: New test. From-SVN: r269308 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/vect/pr89535.f90 | 18 +++++++++++++++++ gcc/tree-vect-stmts.c | 23 ++++++++++++++-------- 4 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/vect/pr89535.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be1cbe57444..4516510751d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-03-01 Richard Sandiford + + PR tree-optimization/89535 + * tree-vect-stmts.c (vectorizable_call): Record the vector types + for each operand. Calculate the fallback choice for mask operands + and pass it to vect_get_vec_def_for_operand. + 2019-03-01 Richard Biener PR middle-end/89541 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f6a8e6a4438..2ad0d80f04a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-01 Richard Sandiford + + PR tree-optimization/89535 + * gfortran.dg/vect/pr89535.f90: New test. + 2019-03-01 Richard Biener PR middle-end/89541 diff --git a/gcc/testsuite/gfortran.dg/vect/pr89535.f90 b/gcc/testsuite/gfortran.dg/vect/pr89535.f90 new file mode 100644 index 00000000000..3e2e9976fdc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/vect/pr89535.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } + +subroutine foo(tmp1, tmp2, tmp3) + integer, parameter :: n = 100 + real :: tmp1(n,2), tmp2(n), tmp3(n) + integer :: i, c1, c2, c3 + logical :: cond + common c1, c2, c3 + + c2 = c3 + cond = c1 .eq. 1 .and. c3 .eq. 1 + do i = 1,100 + if (cond) tmp2(i) = tmp1(i,1) / tmp1(i,2) + end do + do i = 1,100 + if (cond) tmp3(i) = tmp2(i) + end do +end subroutine foo diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 4359fc9978a..6c631db9039 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -3123,6 +3123,7 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, enum vect_def_type dt[4] = { vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type, vect_unknown_def_type }; + tree vectypes[ARRAY_SIZE (dt)] = {}; int ndts = ARRAY_SIZE (dt); int ncopies, j; auto_vec vargs; @@ -3182,10 +3183,8 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, for (i = 0; i < nargs; i++) { - tree opvectype; - op = gimple_call_arg (stmt, i); - if (!vect_is_simple_use (op, vinfo, &dt[i], &opvectype)) + if (!vect_is_simple_use (op, vinfo, &dt[i], &vectypes[i])) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -3211,9 +3210,9 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, rhs_type = TREE_TYPE (op); if (!vectype_in) - vectype_in = opvectype; - else if (opvectype - && opvectype != vectype_in) + vectype_in = vectypes[i]; + else if (vectypes[i] + && vectypes[i] != vectype_in) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -3446,12 +3445,19 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, continue; } + if (mask_opno >= 0 && !vectypes[mask_opno]) + { + gcc_assert (modifier != WIDEN); + vectypes[mask_opno] + = build_same_sized_truth_vector_type (vectype_in); + } + for (i = 0; i < nargs; i++) { op = gimple_call_arg (stmt, i); if (j == 0) vec_oprnd0 - = vect_get_vec_def_for_operand (op, stmt_info); + = vect_get_vec_def_for_operand (op, stmt_info, vectypes[i]); else vec_oprnd0 = vect_get_vec_def_for_stmt_copy (vinfo, orig_vargs[i]); @@ -3584,7 +3590,8 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, if (j == 0) { vec_oprnd0 - = vect_get_vec_def_for_operand (op, stmt_info); + = vect_get_vec_def_for_operand (op, stmt_info, + vectypes[i]); vec_oprnd1 = vect_get_vec_def_for_stmt_copy (vinfo, vec_oprnd0); } -- 2.30.2