public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: richard.guenther@gmail.com (Richard Guenther)
Cc: ira.rosen@linaro.org (Ira Rosen),
	gcc-patches@gcc.gnu.org,
	       patches@linaro.org (Patch Tracking)
Subject: Re: [patch] Fix PR tree-optimization/49771
Date: Mon, 25 Jul 2011 13:47:00 -0000	[thread overview]
Message-ID: <201107251322.p6PDMLDJ019090@d06av02.portsmouth.uk.ibm.com> (raw)
In-Reply-To: <CAFiYyc1=gu_SjCiOj74TkWCrkLcupdKe2fe15K9o=0X5WZvnJQ@mail.gmail.com> from "Richard Guenther" at Jul 25, 2011 01:26:33 PM

Richard Guenther wrote:

> >>>>>> Well, the back-end assumes a pointer to vector type is always
> >>>>>> naturally aligned, and therefore the data it points to can be
> >>>>>> accessed via a simple load, with no extra rotate needed.
> >>>>>
> >>>>> I can't see any use of VECTOR_TYPE in config/spu/, and assuming
> >>>>> anything about alignment just because of the kind of the pointer
> >>>>> is bogus - the scalar code does a scalar read using that pointer.
> >>>>> So the backend better should look at the memory operation, not
> >>>>> at the pointer type.  That said, I can't find any code that looks
> >>>>> suspicious in the spu backend.
> >>>>>
> >>>>>> It seems what happened here is that somehow, a pointer to int
> >>>>>> gets replaced by a pointer to vector, even though their alignment
> >>>>>> properties are different.
> >>>>>
> >>>>> No, they are not.  They get replaced if they are value-equivalent
> >>>>> in which case they are also alignment-equivalent.  But well, the
> >>>>> dump snippet wasn't complete and I don't feel like building a
> >>>>> SPU cross to verify myself.

> > Seems perfectly valid to me.  Or well - I suppose we might run into
> > the issue that the vectorizer sets alignment data at the wrong spot?
> > You can check alignment info when dumping with the -alias flag.
> > Building a spu cross now.
> 
> Nope, all perfectly valid.

Ah, I guess I see what's happening here.  When the SPU back-end is called
to expand the load, the source operand is passed as:

(mem:SI (reg/f:SI 226 [ vect_pa.9 ])
        [2 MEM[base: vect_pa.9_44, offset: 0B]+0 S4 A32])

Now this does say the MEM is only guaranteed to be aligned to 32 bits.

However, spu_expand_load then goes and looks at the components of the
address in detail, in order to figure out how to best perform the access.
In doing so, it looks at the REGNO_POINTER_ALIGN values of the base
registers involved in the address.

In this case, REGNO_POINTER_ALIGN (226) is set to 128, and therefore
the back-end thinks it can use an aligned access after all.

Now, the reason why REGNO_POINTER_ALIGN (226) is 128 is that the register
is the DECL_RTL for the variable vect_pa.9, and that variable has a
pointer-to-vector type (with target alignment 128).

When expanding that variable, expand_one_register_var does:

  if (POINTER_TYPE_P (type))
    mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (type)));

All this is normally completely correct -- a variable of type pointer
to vector type *must* hold only properly aligned values.

I guess the vectorizer deliberatly loads a (potentially) unaligned
value into a vector pointer variable.  It then generates a check
whether the value is really aligned; and uses it only if so.

But if that pointer variable "escapes" into the other branch because
DOM thinks it can re-use the value, the REGNO_POINTER_ALIGN value
carried for its DECL_RTL register is now incorrect ...

Maybe the vectorizer ought to declare that variable with a non-default
type alignment setting?  Or else, perform the assignment to the
variable only *inside* the "if" that checks for correct alignment?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

  reply	other threads:[~2011-07-25 13:22 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-19  8:24 Ira Rosen
2011-07-19  9:49 ` Richard Guenther
2011-07-19 14:01   ` Ira Rosen
2011-07-19 14:03     ` Richard Guenther
2011-07-20 19:47 ` Ulrich Weigand
2011-07-21 12:54   ` Ira Rosen
2011-07-24 14:32     ` Ira Rosen
2011-07-24 18:46       ` Richard Guenther
2011-07-25  9:44         ` Ulrich Weigand
2011-07-25 10:08           ` Richard Guenther
2011-07-25 11:26             ` Ira Rosen
2011-07-25 11:41               ` Richard Guenther
2011-07-25 12:33                 ` Ira Rosen
2011-07-25 13:01                   ` Richard Guenther
2011-07-25 13:07                     ` Richard Guenther
2011-07-25 13:47                       ` Ulrich Weigand [this message]
2011-07-25 14:01                         ` Richard Guenther
2011-07-25 14:10                           ` Richard Guenther
2011-07-25 14:14                             ` Richard Guenther
2011-07-25 14:54                               ` Ulrich Weigand
2011-07-25 14:59                                 ` Richard Guenther
2011-07-25 16:12                                   ` Ulrich Weigand
2011-07-26  8:25                                     ` Richard Guenther
2011-07-26  8:59                                       ` Andrew Pinski
2011-07-26 14:23                                       ` Ulrich Weigand
2011-07-26 14:25                                         ` Michael Matz
2011-07-26 16:18                                           ` Merge alignments from coalesced SSA pointers Michael Matz
2011-07-26 17:23                                             ` Michael Matz
2011-08-08 16:34                                               ` Ulrich Weigand
2011-08-09 12:01                                                 ` Michael Matz
2011-08-12 16:41                                                   ` [rfa] Set alignment of pseudos via get_pointer_alignment Michael Matz
2011-08-12 22:53                                                     ` Richard Guenther
2011-08-23 15:04                                                       ` Michael Matz
2011-07-26 17:28                                             ` Merge alignments from coalesced SSA pointers Ulrich Weigand
2011-07-27  9:13                                               ` Richard Guenther

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201107251322.p6PDMLDJ019090@d06av02.portsmouth.uk.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ira.rosen@linaro.org \
    --cc=patches@linaro.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).