[backport proposed gcc-4.9/trunk bug fix in C++ FE for vector/scalar ops ] List-Archive: Date: Fri, 26 Apr 2013 14:23:32 +0200 (CEST) From: Marc Glisse Subject: 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 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 > > gcc/cp/ > * typeck.c (cp_build_binary_op): Call save_expr before > build_vector_from_val. > > gcc/testsuite/ > * c-c++-common/vector-scalar-2.c: New testcase. --- gcc-4.8.0/gcc/cp/typeck.c.~1~ 2013-03-11 17:22:16.000000000 +0100 +++ gcc-4.8.0/gcc/cp/typeck.c 2013-04-30 12:46:45.908332128 +0200 @@ -3939,7 +3939,7 @@ cp_build_binary_op (location_t location, return error_mark_node; case stv_firstarg: { - op0 = convert (TREE_TYPE (type1), op0); + op0 = save_expr (convert (TREE_TYPE (type1), op0)); op0 = build_vector_from_val (type1, op0); type0 = TREE_TYPE (op0); code0 = TREE_CODE (type0); @@ -3948,7 +3948,7 @@ cp_build_binary_op (location_t location, } case stv_secondarg: { - op1 = convert (TREE_TYPE (type0), op1); + op1 = save_expr (convert (TREE_TYPE (type0), op1)); op1 = build_vector_from_val (type0, op1); type1 = TREE_TYPE (op1); code1 = TREE_CODE (type1); --- gcc-4.8.0/gcc/testsuite/c-c++-common/vector-scalar-2.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.8.0/gcc/testsuite/c-c++-common/vector-scalar-2.c 2013-04-30 12:46:45.908332128 +0200 @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-gimple" } */ + +typedef int veci __attribute__ ((vector_size (4 * sizeof (int)))); + +int c; + +void f (veci *a) +{ + *a = *a + ++c; +} + +/* { dg-final { scan-tree-dump-times " \\\+ 1" 1 "gimple" } } */ +/* { dg-final { cleanup-tree-dump "gimple" } } */