Fix vectorizable_mask_load_store handling of invariant masks
authorRichard Sandiford <richard.sandiford@linaro.org>
Mon, 18 Sep 2017 15:32:01 +0000 (15:32 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 18 Sep 2017 15:32:01 +0000 (15:32 +0000)
vectorizable_mask_load_store was not passing the required mask type to
vect_get_vec_def_for_operand.  This doesn't matter for masks that are
defined in the loop, since their STMT_VINFO_VECTYPE will be what we need
anyway.  But it's not possible to tell which mask type the caller needs
when looking at an invariant scalar boolean.  As the comment above the
function says:

   In case OP is an invariant or constant, a new stmt that creates a vector def
   needs to be introduced.  VECTYPE may be used to specify a required type for
   vector invariant.

This fixes the attached testcase for SVE.

2017-09-18  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
* tree-vect-stmts.c (vectorizable_mask_load_store): Pass mask_vectype
to vect_get_vec_def_for_operand when getting the mask operand.

gcc/testsuite/
* gfortran.dg/vect/mask-store-1.f90: New test.

From-SVN: r252932

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/vect/mask-store-1.f90 [new file with mode: 0644]
gcc/tree-vect-stmts.c

index 9142af1bb061b10d4841c51da283f345e4333890..70b73509c4ef7f48d5cbd16ffa4d0ae0248a7212 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-18  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       * tree-vect-stmts.c (vectorizable_mask_load_store): Pass mask_vectype
+       to vect_get_vec_def_for_operand when getting the mask operand.
+
 2017-09-18  Richard Sandiford  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index f2ad8a052ee16cd0656ccf9e6a9ff31c013b4164..a4662844f8450f142a48530eadff4d25be560fd2 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-18  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       * gfortran.dg/vect/mask-store-1.f90: New test.
+
 2017-09-18  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/45033
diff --git a/gcc/testsuite/gfortran.dg/vect/mask-store-1.f90 b/gcc/testsuite/gfortran.dg/vect/mask-store-1.f90
new file mode 100644 (file)
index 0000000..83cd8dd
--- /dev/null
@@ -0,0 +1,11 @@
+subroutine foo(a, b, x, n)
+  real(kind=8) :: a(n), b(n), tmp
+  logical(kind=1) :: x
+  integer(kind=4) :: i, n
+  do i = 1, n
+     if (x) then
+        a(i) = b(i)
+     end if
+     b(i) = b(i) + 10
+  end do
+end subroutine
index 852e5cdf183a34e122e5f3d6d41bcbec4a4dc062..8f0d3d0909614c6e31c59df4983481c5e7983cbf 100644 (file)
@@ -2331,7 +2331,8 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
            {
              tree rhs = gimple_call_arg (stmt, 3);
              vec_rhs = vect_get_vec_def_for_operand (rhs, stmt);
-             vec_mask = vect_get_vec_def_for_operand (mask, stmt);
+             vec_mask = vect_get_vec_def_for_operand (mask, stmt,
+                                                      mask_vectype);
              /* We should have catched mismatched types earlier.  */
              gcc_assert (useless_type_conversion_p (vectype,
                                                     TREE_TYPE (vec_rhs)));
@@ -2388,7 +2389,8 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
 
          if (i == 0)
            {
-             vec_mask = vect_get_vec_def_for_operand (mask, stmt);
+             vec_mask = vect_get_vec_def_for_operand (mask, stmt,
+                                                      mask_vectype);
              dataref_ptr = vect_create_data_ref_ptr (stmt, vectype, NULL,
                                                      NULL_TREE, &dummy, gsi,
                                                      &ptr_incr, false, &inv_p);