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?).
Confirmed.
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)
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...
(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.
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]
(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.
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
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
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)
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)
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.
Another piece that would be nice: scalar1 ? vector : scalar2 (we already perform the conversion from scalar2 to vector when the condition is a vector)
(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.
*** Bug 58422 has been marked as a duplicate of this bug. ***
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.
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
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.