Bug 67800 - [6 Regression] Missed vectorization opportunity on x86 (DOT_PROD_EXPR in non-reduction)
Summary: [6 Regression] Missed vectorization opportunity on x86 (DOT_PROD_EXPR in non-...
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Richard Biener
Keywords: missed-optimization
Depends on: 67612
Blocks: vectorizer
  Show dependency treegraph
Reported: 2015-10-01 15:48 UTC by Alexander Fomin
Modified: 2016-02-28 10:07 UTC (History)
4 users (show)

See Also:
Target: i686-*-*
Known to work:
Known to fail:
Last reconfirmed: 2015-10-02 00:00:00

A reproducer (295 bytes, text/plain)
2015-10-01 15:48 UTC, Alexander Fomin

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Fomin 2015-10-01 15:48:20 UTC
Created attachment 36434 [details]
A reproducer

A loop in the test attached compiled with -m32 -msse4.2 -O2 -ftree-vectorize -fPIE -pie -c is no more vectorized after r223525 (while on r223524 everything is OK) because of strange DOT_PROD_EXPR recognition (see below).

vect_is_simple_use: operand _15
def_stmt: _15 = _14 * 76;
type of def: internal
vect_recog_dot_prod_pattern: detected: patt_47 = DOT_PROD_EXPR <_2, 76, _17>;
pattern recognized: patt_47 = DOT_PROD_EXPR <_2, 76, _17>;
Comment 1 Alexander Fomin 2015-10-01 16:17:50 UTC
Nota bene: -fPIE -pie options can be ommited.
Comment 2 Richard Biener 2015-10-02 09:32:59 UTC
Mine.  I think this particular issue was also noticed in another bug.
Comment 3 Igor Zamyatin 2015-10-29 08:35:24 UTC
Richard, do you have any plans regarding this?
Comment 4 Richard Biener 2015-10-29 09:54:11 UTC
The other bug was PR67612.  I have a half-way started DOT_PPROD (and SAD_EXPR)
support in vectorizable_conversion but it's not trivial as it doesn't fit there
very.  I've got distracted meanwhile.

A way to fix the regressions (but not PR67612) is to revert the reduction
check parts of

2015-05-22  Richard Biener  <rguenther@suse.de>

        * tree-vect-patterns.c (vect_recog_dot_prod_pattern): Replace
        assert with guard, remove check on detected reduction.
        (vect_recog_sad_pattern): Likewise.
        (vect_recog_widen_sum_pattern): Likewise.

which was preparation for BB vectorization support for reductions (which
I didn't get to finish).

But I'd rather have non-reduction support for DOT_PROD and SAD_EXPR and hope
to get to that during stage3.

If you can beat me to it more power to you ;)
Comment 5 Alexander Fomin 2015-12-01 15:59:14 UTC
Richard, are there any updates on this?

If BB vectorization support for reductions does not fit your plans for stage3, we'd like to fix the regression by doing a partial revert described above.
Comment 6 rguenther@suse.de 2015-12-02 08:21:33 UTC
On Tue, 1 Dec 2015, afomin.mailbox at gmail dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67800
> --- Comment #5 from Alexander Fomin <afomin.mailbox at gmail dot com> ---
> Richard, are there any updates on this?
> If BB vectorization support for reductions does not fit your plans for stage3,
> we'd like to fix the regression by doing a partial revert described above.

I will fix this PR in stage3 by either improving vectoirzation here
or partially reverting the commit.  Stay tuned.
Comment 7 Richard Biener 2015-12-02 13:00:34 UTC
Ah, so reverting these changes causes

FAIL: gcc.dg/vect/slp-reduc-sad.c scan-tree-dump vect "vectorizing stmts using SLP"
FAIL: gcc.dg/vect/slp-reduc-sad.c scan-tree-dump-times vect "vectorized 1 loops" 1

with similar testcases using a dot product or widening sum pattern would
need to be added.  Note that the above are in reduction context but only
the first stmt of the reduction chain is marked as such.

Thus we need to amend the check with ! STMT_VINFO_GROUP_FIRST_ELEMENT (stmt_vinfo).

Testing that now.
Comment 8 Richard Biener 2015-12-03 08:43:54 UTC
Author: rguenth
Date: Thu Dec  3 08:43:22 2015
New Revision: 231221

URL: https://gcc.gnu.org/viewcvs?rev=231221&root=gcc&view=rev
2015-12-03  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/67800
	PR tree-optimization/68333
	* tree-vect-patterns.c (vect_recog_dot_prod_pattern): Restore
	restriction to reduction contexts but allow SLP reductions as well.
	(vect_recog_sad_pattern): Likewise.
	(vect_recog_widen_sum_pattern): Likewise.

	* gcc.target/i386/vect-pr67800.c: New testcase.

Comment 9 Richard Biener 2015-12-03 09:18:37 UTC
Comment 10 Alexander Fomin 2016-02-28 10:07:36 UTC
Thanks, closing it.