Bug 54427 - Expose more vector extensions
Summary: Expose more vector extensions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 58422 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-30 20:07 UTC by Marc Glisse
Modified: 2014-10-03 20:21 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-09-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Glisse 2012-08-30 20:07:18 UTC
Hello,

for gcc's vector extension to be really useful, we need a way to access a large enough subset of operations on vectors in a target-independent way. C exposes comparisons (< <= > >= == !=) and shifts (<< >>), but C++ doesn't. Either these operators should be implemented in the C++ front-end as well, or some builtins should be provided with the same role (__builtin_vec_less?).
Comment 1 Richard Biener 2012-09-03 10:37:58 UTC
Confirmed.
Comment 2 Marc Glisse 2012-09-14 17:17:08 UTC
Author: glisse
Date: Fri Sep 14 17:17:01 2012
New Revision: 191308

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191308
Log:
2012-09-14  Marc Glisse  <marc.glisse@inria.fr>
	PR c++/54427

gcc/ChangeLog
	* fold-const.c (fold_unary_loc): Disable for VECTOR_TYPE.
	(fold_binary_loc): Likewise.
	* gimple-fold.c (and_comparisons_1): Handle VECTOR_TYPE.
	(or_comparisons_1): Likewise.

gcc/cp/ChangeLog
	* typeck.c (cp_build_binary_op) [LSHIFT_EXPR, RSHIFT_EXPR, EQ_EXPR,
	NE_EXPR, LE_EXPR, GE_EXPR, LT_EXPR, GT_EXPR]: Handle VECTOR_TYPE.

gcc/testsuite/ChangeLog
	* g++.dg/other/vector-compare.C: New testcase.
	* gcc/testsuite/c-c++-common/vector-compare-3.c: New testcase.
	* gcc.dg/vector-shift.c: Move ...
	* c-c++-common/vector-shift.c: ... here.
	* gcc.dg/vector-shift1.c: Move ...
	* c-c++-common/vector-shift1.c: ... here.
	* gcc.dg/vector-shift3.c: Move ...
	* c-c++-common/vector-shift3.c: ... here.
	* gcc.dg/vector-compare-1.c: Move ...
	* c-c++-common/vector-compare-1.c: ... here.
	* gcc.dg/vector-compare-2.c: Move ...
	* c-c++-common/vector-compare-2.c: ... here.
	* gcc.c-torture/execute/vector-compare-1.c: Move ...
	* c-c++-common/torture/vector-compare-1.c: ... here.
	* gcc.c-torture/execute/vector-compare-2.x: Delete.
	* gcc.c-torture/execute/vector-compare-2.c: Move ...
	* c-c++-common/torture/vector-compare-2.c: ... here.
	* gcc.c-torture/execute/vector-shift.c: Move ...
	* c-c++-common/torture/vector-shift.c: ... here.
	* gcc.c-torture/execute/vector-shift2.c: Move ...
	* c-c++-common/torture/vector-shift2.c: ... here.
	* gcc.c-torture/execute/vector-subscript-1.c: Move ...
	* c-c++-common/torture/vector-subscript-1.c: ... here.
	* gcc.c-torture/execute/vector-subscript-2.c: Move ...
	* c-c++-common/torture/vector-subscript-2.c: ... here.
	* gcc.c-torture/execute/vector-subscript-3.c: Move ...
	* c-c++-common/torture/vector-subscript-3.c: ... here.


Added:
    trunk/gcc/testsuite/c-c++-common/torture/vector-compare-1.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-compare-1.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-compare-2.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-compare-2.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-shift.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-shift2.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift2.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-subscript-1.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-1.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-subscript-2.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-2.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-subscript-3.c
      - copied, changed from r190838, trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-3.c
    trunk/gcc/testsuite/c-c++-common/vector-compare-1.c
      - copied, changed from r190834, trunk/gcc/testsuite/gcc.dg/vector-compare-1.c
    trunk/gcc/testsuite/c-c++-common/vector-compare-2.c
      - copied unchanged from r190834, trunk/gcc/testsuite/gcc.dg/vector-compare-2.c
    trunk/gcc/testsuite/c-c++-common/vector-compare-3.c   (with props)
    trunk/gcc/testsuite/c-c++-common/vector-shift.c
      - copied, changed from r190834, trunk/gcc/testsuite/gcc.dg/vector-shift.c
    trunk/gcc/testsuite/c-c++-common/vector-shift1.c
      - copied, changed from r190834, trunk/gcc/testsuite/gcc.dg/vector-shift1.c
    trunk/gcc/testsuite/c-c++-common/vector-shift3.c
      - copied, changed from r190834, trunk/gcc/testsuite/gcc.dg/vector-shift3.c
    trunk/gcc/testsuite/g++.dg/other/vector-compare.C   (with props)
Removed:
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-compare-1.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-compare-2.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-compare-2.x
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift2.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-1.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-2.c
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-subscript-3.c
    trunk/gcc/testsuite/gcc.dg/vector-compare-1.c
    trunk/gcc/testsuite/gcc.dg/vector-compare-2.c
    trunk/gcc/testsuite/gcc.dg/vector-shift.c
    trunk/gcc/testsuite/gcc.dg/vector-shift1.c
    trunk/gcc/testsuite/gcc.dg/vector-shift3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/fold-const.c
    trunk/gcc/gimple-fold.c
    trunk/gcc/testsuite/ChangeLog

Propchange: trunk/gcc/testsuite/c-c++-common/vector-compare-3.c
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/c-c++-common/vector-compare-3.c
            ('svn:keywords' added)

Propchange: trunk/gcc/testsuite/g++.dg/other/vector-compare.C
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/g++.dg/other/vector-compare.C
            ('svn:keywords' added)
Comment 3 Marc Glisse 2012-09-14 17:22:24 UTC
Progress :-)

Documentation update is needed.

Next useful one would be ?: so we can generate vec_cond_expr. See the OpenCL specification for a list of what's missing.

Another useful thing would be to audit the optimization passes that don't expect vectors and mishandle them...
Comment 4 Pat Haugen 2012-09-20 19:00:47 UTC
(In reply to comment #2)
>     * gcc.c-torture/execute/vector-compare-2.c: Move ...
>     * c-c++-common/torture/vector-compare-2.c: ... here.

This test is now failing on powerpc64-unknown-linux-gnu due to warning messages being emitted for 32-bit.

FAIL: c-c++-common/torture/vector-compare-2.c  -O0  (test for excess errors)
FAIL: c-c++-common/torture/vector-compare-2.c  -O1  (test for excess errors)
...

This is due to the fact that in the old location the compile command included -w which suppressed warnings, whereas the new location does not. The test can be fixed for powerpc by adding the following line (as is present in c-c++-common/vector-compare-2.c).

/* { dg-options "-mabi=altivec" { target { { powerpc*-*-linux* } && ilp32 } } } */

But it looks like this same test started failing on i686-pc-linux-gnu (http://gcc.gnu.org/ml/gcc-testresults/2012-09/msg01842.html), guessing for the same reason. Not sure if there's some similar type option that can be added for that target or whether '-w' should just be added to the testcase.
Comment 5 Pat Haugen 2012-09-20 19:13:25 UTC
Forgot to include the error message, which is causing the failures:

/home/pthaugen/src/gcc/trunk/gcc/gcc/testsuite/c-c++-common/torture/vector-compare-2.c:9:1: warning: GCC vector passed by reference: non-standard ABI extension with no compatibility guarantee [enabled by default]
Comment 6 Marc Glisse 2012-09-20 19:46:57 UTC
(In reply to comment #4)
> This test is now failing on powerpc64-unknown-linux-gnu due to warning messages
> being emitted for 32-bit.

I was kind of expecting that (mentioned in the patch submission) but couldn't see what I was changing by moving the test.

> This is due to the fact that in the old location the compile command included
> -w which suppressed warnings, whereas the new location does not.

Ah, thanks a lot! I didn't realize there was an automatic -w in the old location.

> The test can
> be fixed for powerpc by adding the following line (as is present in
> c-c++-common/vector-compare-2.c).
> 
> /* { dg-options "-mabi=altivec" { target { { powerpc*-*-linux* } && ilp32 } } }
> */
> 
> But it looks like this same test started failing on i686-pc-linux-gnu
> (http://gcc.gnu.org/ml/gcc-testresults/2012-09/msg01842.html), guessing for the
> same reason. Not sure if there's some similar type option that can be added for
> that target or whether '-w' should just be added to the testcase.

Yes, I think adding -w is the easiest solution (after all that's just reverting to the old behavior). Otherwise the test could be changed to pass arguments by pointer like the others, but I didn't dare do that in case it was specifically testing passing by value.

I'll submit the -w ASAP, thanks again.
Comment 7 Marc Glisse 2012-09-21 09:19:47 UTC
Author: glisse
Date: Fri Sep 21 09:19:39 2012
New Revision: 191604

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191604
Log:
2012-09-21  Marc Glisse  <marc.glisse@inria.fr>

	PR c++/54427
	* c-c++-common/torture/vector-compare-2.c: Add -w.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/c-c++-common/torture/vector-compare-2.c
Comment 8 Marc Glisse 2012-09-27 10:06:29 UTC
Author: glisse
Date: Thu Sep 27 10:06:23 2012
New Revision: 191800

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191800
Log:
2012-09-27  Marc Glisse  <marc.glisse@inria.fr>

	PR c/53024
	PR c++/54427
	* gcc/doc/extend.texi (Vector Extensions): C++ improvements.
	Power of 2 size requirement.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/extend.texi
Comment 9 Marc Glisse 2012-10-09 06:18:35 UTC
Author: glisse
Date: Tue Oct  9 06:18:29 2012
New Revision: 192238

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192238
Log:
2012-10-09  Marc Glisse  <marc.glisse@inria.fr>

	PR c++/54427

c/
	* c-typeck.c: Include c-common.h.
	(enum stv_conv): Moved to c-common.h.
	(scalar_to_vector): Moved to c-common.c.
	(build_binary_op): Adapt to scalar_to_vector's new prototype.
	* Make-lang.in: c-typeck.c depends on c-common.h.

c-family/
	* c-common.c (scalar_to_vector): Moved from c-typeck.c. Support
	more operations. Make error messages optional.
	* c-common.h (enum stv_conv): Moved from c-typeck.c.
	(scalar_to_vector): Declare.

cp/
	* typeck.c (cp_build_binary_op): Handle mixed scalar-vector
	operations.
	[LSHIFT_EXPR, RSHIFT_EXPR]: Likewise.

gcc/
	* fold-const.c (fold_binary_loc): Use build_zero_cst instead of
	build_int_cst for a potential vector.

testsuite/
	* c-c++-common/vector-scalar.c: New testcase.
	* g++.dg/ext/vector18.C: New testcase.
	* g++.dg/ext/vector5.C: This is not an error anymore.
	* gcc.dg/init-vec-1.c: Move ...
	* c-c++-common/init-vec-1.c: ... here. Adapt error message.
	* gcc.c-torture/execute/vector-shift1.c: Move ...
	* c-c++-common/torture/vector-shift1.c: ... here.
	* gcc.dg/scal-to-vec1.c: Move ...
	* c-c++-common/scal-to-vec1.c: ... here. Avoid narrowing for
	C++11. Adapt error messages.
	* gcc.dg/convert-vec-1.c: Move ...
	* c-c++-common/convert-vec-1.c: ... here.
	* gcc.dg/scal-to-vec2.c: Move ...
	* c-c++-common/scal-to-vec2.c: ... here.


Added:
    trunk/gcc/testsuite/c-c++-common/convert-vec-1.c
      - copied unchanged from r191610, trunk/gcc/testsuite/gcc.dg/convert-vec-1.c
    trunk/gcc/testsuite/c-c++-common/init-vec-1.c
      - copied, changed from r191610, trunk/gcc/testsuite/gcc.dg/init-vec-1.c
    trunk/gcc/testsuite/c-c++-common/scal-to-vec1.c
      - copied, changed from r191610, trunk/gcc/testsuite/gcc.dg/scal-to-vec1.c
    trunk/gcc/testsuite/c-c++-common/scal-to-vec2.c
      - copied unchanged from r191610, trunk/gcc/testsuite/gcc.dg/scal-to-vec2.c
    trunk/gcc/testsuite/c-c++-common/torture/vector-shift1.c
      - copied, changed from r191610, trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift1.c
    trunk/gcc/testsuite/c-c++-common/vector-scalar.c   (with props)
    trunk/gcc/testsuite/g++.dg/ext/vector18.C   (with props)
Removed:
    trunk/gcc/testsuite/gcc.c-torture/execute/vector-shift1.c
    trunk/gcc/testsuite/gcc.dg/convert-vec-1.c
    trunk/gcc/testsuite/gcc.dg/init-vec-1.c
    trunk/gcc/testsuite/gcc.dg/scal-to-vec1.c
    trunk/gcc/testsuite/gcc.dg/scal-to-vec2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/c-family/c-common.h
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/Make-lang.in
    trunk/gcc/c/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/ext/vector5.C

Propchange: trunk/gcc/testsuite/c-c++-common/vector-scalar.c
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/c-c++-common/vector-scalar.c
            ('svn:keywords' added)

Propchange: trunk/gcc/testsuite/g++.dg/ext/vector18.C
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/g++.dg/ext/vector18.C
            ('svn:keywords' added)
Comment 10 Marc Glisse 2012-10-25 13:02:48 UTC
Author: glisse
Date: Thu Oct 25 13:02:42 2012
New Revision: 192808

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192808
Log:
2012-10-25  Marc Glisse  <marc.glisse@inria.fr>

	PR c++/54427

gcc/
	* tree.c (signed_or_unsigned_type_for): Handle vectors.

gcc/cp/
	* typeck.c (build_x_conditional_expr): Handle VEC_COND_EXPR.
	* call.c (build_conditional_expr_1): Likewise.

gcc/c-family/
	* c-common.c (scalar_to_vector): Handle VEC_COND_EXPR.

gcc/testsuite/
	* g++.dg/ext/vector19.C: New testcase.


Added:
    trunk/gcc/testsuite/g++.dg/ext/vector19.C   (with props)
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c

Propchange: trunk/gcc/testsuite/g++.dg/ext/vector19.C
            ('svn:eol-style' added)

Propchange: trunk/gcc/testsuite/g++.dg/ext/vector19.C
            ('svn:keywords' added)
Comment 11 Marc Glisse 2012-10-25 13:17:06 UTC
From a front-end perspective, we are getting close. Some remaining items:
- port ?: to the C front-end (I don't know the maybe_const stuff)
- support &&, ||, !
- make sure everything works with constexpr
- there is another PR about having a way to call sqrt on a vector
- (big item) have a better interface than an attribute, something that can be deduced in template contexts as easily as std::array<type,nelts>...

There is more work in the middle-end.
Comment 12 Marc Glisse 2013-04-12 13:59:33 UTC
Another piece that would be nice:
scalar1 ? vector : scalar2

(we already perform the conversion from scalar2 to vector when the condition is a vector)
Comment 13 Marc Glisse 2013-05-07 21:59:08 UTC
(In reply to comment #11)
> - support &&, ||, !

A patch was posted at:
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00783.html

but the only answer was against supporting the logical operators for vectors.
Comment 14 Marc Glisse 2013-09-14 21:42:35 UTC
*** Bug 58422 has been marked as a duplicate of this bug. ***
Comment 15 Marc Glisse 2013-11-10 08:55:27 UTC
Related PRs involving || and && for vectors: PR 57198 and PR 58845.
PR 58845 contains information about having a sequence point in the gimplification of those operators.
Comment 16 Marc Glisse 2014-10-03 19:57:33 UTC
Author: glisse
Date: Fri Oct  3 19:57:01 2014
New Revision: 215872

URL: https://gcc.gnu.org/viewcvs?rev=215872&root=gcc&view=rev
Log:
2014-10-03  Marc Glisse  <marc.glisse@inria.fr>

	PR c++/54427
	PR c++/57198
	PR c++/58845
gcc/c-family/
	* c-common.c (warn_logical_operator): Punt for vectors.
gcc/cp/
	* typeck.c (cp_build_binary_op): save_expr after convert to save
	redundant operations.
	[TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR]: Handle vectors.
	(cp_build_unary_op) [TRUTH_NOT_EXPR]: Likewise.
gcc/
	* doc/extend.texi (Vector Extensions): Document &&, ||, ! in C++.
gcc/testsuite/
	* g++.dg/ext/vector9.C: Update, not an error anymore.
	* g++.dg/ext/vector27.C: Replace with new test.
	* g++.dg/ext/vector28.C: New file.
	* g++.dg/other/error23.C: Update to a different error.


Added:
    trunk/gcc/testsuite/g++.dg/ext/vector28.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/doc/extend.texi
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/ext/vector27.C
    trunk/gcc/testsuite/g++.dg/ext/vector9.C
    trunk/gcc/testsuite/g++.dg/other/error23.C
Comment 17 Marc Glisse 2014-10-03 20:21:19 UTC
I think it is time to close this PR. The main operations have been implemented, most of the remaining ones are tracked in other PRs, and the rest should be as this PR has become too long.