This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix mask type choice in vectorizable_call (PR 89535)
- From: Richard Sandiford <richard dot sandiford at arm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 01 Mar 2019 10:45:19 +0000
- Subject: 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. Really looking
forward to seeing this non-SLP structure go away :-)
Tested on aarch64-linux-gnu (with and without SVE), aarch64_be-elf
and x86_64-linux-gnu. OK to install?
Richard
2019-03-01 Richard Sandiford <richard.sandiford@arm.com>
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.
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c 2019-01-25 12:10:12.913100840 +0000
+++ gcc/tree-vect-stmts.c 2019-03-01 10:43:26.652480564 +0000
@@ -3123,6 +3123,7 @@ vectorizable_call (stmt_vec_info stmt_in
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<tree, 8> vargs;
@@ -3182,10 +3183,8 @@ vectorizable_call (stmt_vec_info stmt_in
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_in
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_in
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_in
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);
}
Index: gcc/testsuite/gfortran.dg/vect/pr89535.f90
===================================================================
--- /dev/null 2019-02-27 08:05:34.202446820 +0000
+++ gcc/testsuite/gfortran.dg/vect/pr89535.f90 2019-03-01 10:43:26.652480564 +0000
@@ -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