This is the mail archive of the
mailing list for the GCC project.
Re: riscv64 dep. computation
- From: Paulo Matos <email@example.com>
- To: Jim Wilson <jimw at sifive dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 15 Feb 2019 08:33:28 +0100
- Subject: Re: riscv64 dep. computation
- References: <firstname.lastname@example.org> <email@example.com>
On 14/02/2019 19:56, Jim Wilson wrote:
> On 2/14/19 3:13 AM, Paulo Matos wrote:
>> If I compile this with -O2, sched1 groups all loads and all stores
>> together. That's perfect. However, if I change TYPE to unsigned char and
>> recompile, the stores and loads are interleaved.
>> Further investigation shows that for unsigned char there are extra
>> dependencies that block the scheduler from grouping stores and loads.
> The ISO C standard says that anything can be casted to char *, and char
> * can be casted to anything. Hence, a char * pointer aliases everything.
> If you look at the alias set info in the MEMs, you can see that the char
> * references are in alias set 0, which means that they alias everything.
> The short * references are in alias set 2 which means they only alias
> other stuff in alias set 2. The difference here is that short * does
> not alias the structure pointers, but char * does. I haven't tried
> debugging your example, but this is presumably where the difference
> comes from.
OK, that seems to make sense. Indeed if I use restrict on the argument
pointers, the compiler will sort itself out and group the loads and stores.
> Because x and y are pointer parameters, the compiler must assume that
> they might alias. And because char * aliases everything, the char
> references alias them too. If you change x and y to global variables,
> then they no longer alias each other, and the compiler will schedule all
> of the loads first, even for char.
Are global variables not supposed to alias each other?
If I indeed do that, gcc still won't group loads and stores: