On Mon, Jun 1, 2020 at 11:09 AM Eric Botcazou <botca...@adacore.com> wrote:
>
> Hi,
>
> this addresses the issue raised by Andrew a few weeks ago about the usage of
> memory copy functions to toggle the scalar storage order.  Recall that you
> cannot (the compiler errors out) take the address of a scalar which is stored
> in reverse order, but you can do it for the enclosing aggregate type., which
> means that you can also pass it to the memory copy functions.  In this case,
> the optimizer may rewrite the copy into a scalar copy, which is a no-no.
>
> The patch also contains an unrelated hunk for the tree pretty printer.
>
> Tested on x86-64/Linux, OK for the mainline?

Hum.  How does the pointer type matter at all for memcpy()?  Isn't the
issue just that we may not use the TYPE_REVERSE_STORAGE_ORDER
qualified type in the following case:

      gimple *new_stmt;
      if (is_gimple_reg_type (TREE_TYPE (srcvar)))
        {
          tree tem = fold_const_aggregate_ref (srcvar);
          if (tem)
            srcvar = tem;
          if (! is_gimple_min_invariant (srcvar))
            {
              new_stmt = gimple_build_assign (NULL_TREE, srcvar);
              srcvar = create_tmp_reg_or_ssa_name (TREE_TYPE (srcvar),
                                                   new_stmt);

?

For the VN case the issue is interpreting a read via memcpy (non
reverse-storage)
as a reverse-storage one when matching up with a hashtable entry from
a regular reverse-storage order store, correct?  But likewise whether the
pointer destination had the attribute doesn't correctly qualify this - instead
I think we are already properly matching up the reverse storage property?
And for a rso lookup we just need to make sure to replace the inner
operands with rso ones here:

      /* The looked-through reference is a simple MEM_REF.  */
      memset (&op, 0, sizeof (op));
      op.type = vr->type;
      op.opcode = MEM_REF;
      op.op0 = build_int_cst (ptr_type_node, at - lhs_offset + rhs_offset);
      op.off = at - lhs_offset + rhs_offset;
      vr->operands[0] = op;
      op.type = TREE_TYPE (rhs);
      op.opcode = TREE_CODE (rhs);
      op.op0 = rhs;
      op.off = -1;
      vr->operands[1] = op;
      vr->hashcode = vn_reference_compute_hash (vr);

or instead guard vr->operands to not have any rso components?

The pretty-print hunk is OK.

Thanks,
Richard.

>
> 2020-06-01  Eric Botcazou  <ebotca...@adacore.com>
>
>         * gimple-fold.c (gimple_fold_builtin_memory_op): Do not replace with a
>         scalar copy if either type has reverse scalar storage order.
>         * tree-ssa-sccvn.c (vn_reference_lookup_3): Do not propagate through a
>         memory copy if either type has reverse scalar storage order.
>
>         * tree-pretty-print.c (dump_generic_node) <ARRAY_TYPE>: Print quals.
>
>
> 2020-06-01  Eric Botcazou  <ebotca...@adacore.com>
>
>         * gcc.c-torture/execute/sso-1.c: New test.
>
> --
> Eric Botcazou

Reply via email to