public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ilya Enkovich <enkovich.gnu@gmail.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Avoid integer vector used as a vector mask
Date: Fri, 11 Dec 2015 09:59:00 -0000	[thread overview]
Message-ID: <20151211095847.GB54845@msticlxl57.ims.intel.com> (raw)

Hi,

Currently when MASK_LOAD and MASK_STORE is vectorized we check
scalar type of a mask but don't check its vector mask.  It means
we may vectorize it when mask was just loaded from an array of
booleans.  This happens e.g. for following test:

SUBROUTINE TEST (x, y, z, mask, ims, ime)
  IMPLICIT NONE
  INTEGER ims, ime, i
  LOGICAL mask (ims:ime)
  REAL x(ims:ime), y(ims:ime), z(ims:ime)

  DO 812 i=ims,ime
     IF (mask(i)) x(i) = y(i) - z(i)
812  CONTINUE
  END

Produced GIMPLE:

  vect__15.30_76 = MEM[base: _91, offset: 0B];
  vect__17.32_80 = MASK_LOAD (vectp_y.33_78, 4B, vect__15.30_76);
  vect__19.35_83 = MASK_LOAD (vectp_z.36_81, 4B, vect__15.30_76);
  vect__20.38_84 = vect__17.32_80 - vect__19.35_83;
  MASK_STORE (vectp_x.39_85, 4B, vect__15.30_76, vect__20.38_84);

Loaded values don't have required all 0s and all 1s values and
shouldn't be used as a mask.  This patch checks vector type of
a mask used for MASK_LOAD and MASK_STORE.  Bootstrapped and
regtested for x86_64-pc-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

2015-12-11  Ilya Enkovich  <enkovich.gnu@gmail.com>

	* tree-vect-stmts.c (vectorizable_mask_load_store): Check
	mask vectype.


diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 5377d15..abcd9a4 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -1780,7 +1780,7 @@ vectorizable_mask_load_store (gimple *stmt, gimple_stmt_iterator *gsi,
   if (!mask_vectype)
     mask_vectype = get_mask_type_for_scalar_type (TREE_TYPE (vectype));
 
-  if (!mask_vectype)
+  if (!mask_vectype || !VECTOR_BOOLEAN_TYPE_P (mask_vectype))
     return false;
 
   if (is_store)

             reply	other threads:[~2015-12-11  9:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11  9:59 Ilya Enkovich [this message]
2015-12-11 10:42 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151211095847.GB54845@msticlxl57.ims.intel.com \
    --to=enkovich.gnu@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).