This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Logic operators ! && || for vectors


Ping http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00783.html

Even if we decide not to implement logic operators in the front-end, we still need the fix for the wrong code (the 2 save_expr in cp_build_binary_op, is that part of the patch ok with the vector-scalar-2.c testcase? and for 4.8?) and to avoid ICEing on __m128i f(__m128d a,__m128d b){return a<b&&b<a;} as we currently do in warn_logical_operator.

On Fri, 12 Apr 2013, Marc Glisse wrote:

Hello,

this adds support for vector !, && and ||. In the long run, I think it would be good to be able to use TRUTH_*_EXPR with vectors, but that's probably a lot of work.

It currently restricts && and || to vector-vector operations. I'd like to also support mixed scalar-vector later, but it is a bit more complicated. With vectors, && evaluates both sides. For scal && vec, we have the choice of making it short-circuit: cond_expr((bool)scal, vec!=0, {0}) or do a vector and. For vec && scal, it seems clear we have to evaluate both operands, but then we can also make it a cond_expr instead of a BIT_AND_EXPR (technically, I think I can achieve that with save_expr and a compound_expr, I don't know if there is a better way to add statements).

The missing save_expr before build_vector_from_val are a bug I introduced when I adapted the code from the C front-end. This bit (and the vector-scalar-2.c testcase that goes with it) should probably be backported to 4.8.

The code we generate for these examples is not very good, but that's a different issue.

Bootstrap+testsuite on x86_64-linux-gnu.

2013-04-12  Marc Glisse  <marc.glisse@inria.fr>

gcc/cp/
	* typeck.c (cp_build_binary_op): Call save_expr before
	build_vector_from_val.
	<TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR, TRUTH_AND_EXPR,
	TRUTH_OR_EXPR>: Handle vectors.
	(cp_build_unary_op) <TRUTH_NOT_EXPR>: Likewise.

gcc/c-family/
	* c-common.c (warn_logical_operator): Give up for vectors.

gcc/testsuite/
	* c-c++-common/vector-scalar-2.c: New testcase.
	* g++.dg/ext/vector22.C: Likewise.
	* g++.dg/ext/vector23.C: Likewise.
	* g++.dg/ext/vector9.C: Adapt.
	* g++.dg/other/error23.C: Adapt.



--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]