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: Vector Comparison patch


On Wed, Aug 17, 2011 at 10:52 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Wed, 17 Aug 2011, Artem Shinkarov wrote:
>
>> +For the convenience condition in the vector conditional can be just a
>> +vector of signed integer type. In that case this vector is implicitly
>> +compared with vectors of zeroes. Consider an example:
>
> Where is this bit tested in the testcases added?

In the gcc.c-torture/execute/vector-vcond-2.c at the end of test-case:

  /* Condition expressed with a single variable.  */
  dres = l0 ? d0 : d1;
  check_compare (2, dres, l0, ((vector (2, long)){-1,-1}), d0, d1, ==,
"%f", "%i");

  lres = l1 ? l0 : l1;
  check_compare (2, lres, l1, ((vector (2, long)){-1,-1}), l0, l1, ==,
"%i", "%i");

  fres = i0 ? f0 : f1;
  check_compare (4, fres, i0, ((vector (4, int)){-1,-1,-1,-1}),
		 f0, f1, ==, "%f", "%i");

  ires = i1 ? i0 : i1;
  check_compare (4, ires, i1, ((vector (4, int)){-1,-1,-1,-1}),
		 i0, i1, ==, "%i", "%i");

>
>> + ? ? ?if (TREE_CODE (type1) != VECTOR_TYPE
>> + ? ? ? || TREE_CODE (type2) != VECTOR_TYPE)
>> + ? ? ? ?{
>> + ? ? ? ? ?error_at (colon_loc, "vector comparisom arguments must be of "
>> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "type vector");
>
> "comparison"

Thanks, adjusted.

>> + ? ? ?/* Avoid C_MAYBE_CONST in VEC_COND_EXPR. ?*/
>> + ? ? ?sc = c_fully_fold (ifexp, false, &maybe_const);
>> + ? ? ?sc = save_expr (sc);
>> + ? ? ?if (!maybe_const)
>> + ? ? ifexp = c_wrap_maybe_const (sc, true);
>> + ? ? ?else
>> + ? ? ifexp = sc;
>
> This looks like it's duplicating c_save_expr; that is, like "ifexp =
> c_save_expr (ifexp);" would suffice.
>
> But, it's not clear that it actually achieves the effect described in the
> comment; have you actually tried with function calls, assignments etc. in
> the operands?

I tested it with gcc.dg/vector-compare-2.c:
typedef int vec __attribute__((vector_size(16)));

vec i,j;
extern vec a, b, c;

vec
foo (int x)
{
  return (x ? i : j) ? a : b;
}

vec
bar (int x)
{
  return a ? (x ? i : j) : b;
}

vec
baz (int x)
{
  return a ? b : (x ? i : j);
}

Is it good enough?

> The code in build_binary_op uses save_expr rather than
> c_save_expr because it does some intermediate operations before calling
> c_wrap_maybe_const, and if you really want to avoid C_MAYBE_CONST in
> VEC_COND_EXPR then you'll need to continue calling save_expr, as here, but
> delay the call to c_wrap_maybe_const so that the whole VEC_COND_EXPR is
> wrapped if required.

Ok, but I need to wrap it at some point, where do you think it would
be appropriate to do?


Thanks,
Artem.


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