public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [SVE] PR86753
@ 2019-08-14 15:53 Prathamesh Kulkarni
  2019-08-14 16:59 ` Richard Biener
  0 siblings, 1 reply; 41+ messages in thread
From: Prathamesh Kulkarni @ 2019-08-14 15:53 UTC (permalink / raw)
  To: gcc Patches, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 2715 bytes --]

Hi,
The attached patch tries to fix PR86753.

For following test:
void
f1 (int *restrict x, int *restrict y, int *restrict z)
{
  for (int i = 0; i < 100; ++i)
    x[i] = y[i] ? z[i] : 10;
}

vect dump shows:
  vect_cst__42 = { 0, ... };
  vect_cst__48 = { 0, ... };

  vect__4.7_41 = .MASK_LOAD (vectp_y.5_38, 4B, loop_mask_40);
  _4 = *_3;
  _5 = z_12(D) + _2;
  mask__35.8_43 = vect__4.7_41 != vect_cst__42;
  _35 = _4 != 0;
  vec_mask_and_46 = mask__35.8_43 & loop_mask_40;
  vect_iftmp.11_47 = .MASK_LOAD (vectp_z.9_44, 4B, vec_mask_and_46);
  iftmp.0_13 = 0;
  vect_iftmp.12_50 = VEC_COND_EXPR <vect__4.7_41 != vect_cst__48,
vect_iftmp.11_47, vect_cst__49>;

and following code-gen:
L2:
        ld1w    z0.s, p2/z, [x1, x3, lsl 2]
        cmpne   p1.s, p3/z, z0.s, #0
        cmpne   p0.s, p2/z, z0.s, #0
        ld1w    z0.s, p0/z, [x2, x3, lsl 2]
        sel     z0.s, p1, z0.s, z1.s

We could reuse vec_mask_and_46 in vec_cond_expr since the conditions
vect__4.7_41 != vect_cst__48 and vect__4.7_41 != vect_cst__42
are equivalent, and vect_iftmp.11_47 depends on vect__4.7_41 != vect_cst__48.

I suppose in general for vec_cond_expr <C, T, E> if T comes from masked load,
which is conditional on C, then we could reuse the mask used in load,
in vec_cond_expr ?

The patch maintains a hash_map cond_to_vec_mask
from <cond, loop_mask -> vec_mask (with loop predicate applied).
In prepare_load_store_mask, we record <cond, loop_mask> -> vec_mask & loop_mask,
and in vectorizable_condition, we check if <cond, loop_mask> exists in
cond_to_vec_mask
and if found, the corresponding vec_mask is used as 1st operand of
vec_cond_expr.

<cond, loop_mask> is represented with cond_vmask_key, and the patch
adds tree_cond_ops to represent condition operator and operands coming
either from cond_expr
or a gimple comparison stmt. If the stmt is not comparison, it returns
<ne_expr, lhs, 0> and inserts that into cond_to_vec_mask.

With patch, the redundant p1 is eliminated and sel uses p0 for above test.

For following test:
void
f2 (int *restrict x, int *restrict y, int *restrict z, int fallback)
{
  for (int i = 0; i < 100; ++i)
    x[i] = y[i] ? z[i] : fallback;
}

input to vectorizer has operands swapped in cond_expr:
  _36 = _4 != 0;
  iftmp.0_14 = .MASK_LOAD (_5, 32B, _36);
  iftmp.0_8 = _4 == 0 ? fallback_12(D) : iftmp.0_14;

So we need to check for inverted condition in cond_to_vec_mask,
and swap the operands.
Does the patch look OK so far ?

One major issue remaining with the patch is value  numbering.
Currently, it does value numbering for entire function using sccvn
during start of vect pass, which is too expensive since we only need
block based VN. I am looking into that.

Thanks,
Prathamesh

[-- Attachment #2: pr86753-5.diff --]
[-- Type: application/x-patch, Size: 11197 bytes --]

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2019-10-18  5:15 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14 15:53 [SVE] PR86753 Prathamesh Kulkarni
2019-08-14 16:59 ` Richard Biener
2019-08-14 17:01   ` Richard Biener
2019-08-14 21:22     ` Richard Sandiford
2019-08-21 20:10       ` Prathamesh Kulkarni
2019-08-22 12:05         ` Richard Biener
2019-08-23 12:46           ` Prathamesh Kulkarni
2019-08-23 13:47             ` Richard Sandiford
2019-08-23 14:30               ` Prathamesh Kulkarni
2019-08-23 14:34                 ` Richard Sandiford
2019-08-26  5:59                   ` Prathamesh Kulkarni
2019-08-26 11:46                     ` Richard Biener
2019-08-26 13:39                       ` Prathamesh Kulkarni
2019-08-27 10:41                         ` Richard Sandiford
2019-08-27 11:31                           ` Richard Biener
2019-08-27 12:52                             ` Richard Sandiford
2019-08-27 15:55                               ` Prathamesh Kulkarni
2019-08-27 17:39                                 ` Richard Sandiford
2019-08-27 20:10                                   ` Prathamesh Kulkarni
2019-08-28  9:42                                     ` Richard Sandiford
2019-08-30 12:09                                       ` Richard Biener
2019-08-31 16:56                                         ` Prathamesh Kulkarni
2019-09-05  9:00                                           ` Richard Sandiford
2019-09-05 12:51                                             ` Prathamesh Kulkarni
2019-09-09 11:15                                               ` Richard Sandiford
2019-09-09 16:37                                                 ` Prathamesh Kulkarni
2019-09-09 20:56                                                   ` Prathamesh Kulkarni
2019-09-10 12:20                                                     ` Richard Sandiford
2019-09-10 13:35                                                     ` Matthew Malcomson
2019-09-10 21:36                                                       ` Prathamesh Kulkarni
2019-09-16 15:54                                                   ` Prathamesh Kulkarni
2019-09-25 16:18                                                     ` Prathamesh Kulkarni
2019-10-02 23:42                                                       ` Prathamesh Kulkarni
2019-10-04 10:38                                                         ` Richard Biener
2019-10-08  0:10                                                           ` Prathamesh Kulkarni
2019-10-08  7:51                                                             ` Richard Sandiford
2019-10-09  3:23                                                               ` Prathamesh Kulkarni
2019-10-15  6:11                                                                 ` Prathamesh Kulkarni
2019-10-15 11:40                                                                   ` Richard Biener
2019-10-16 12:13                                                                     ` Richard Sandiford
2019-10-18  5:20                                                                       ` Prathamesh Kulkarni

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).