* Restrict keyword doesn't work correctly in GCC 4.4
@ 2009-06-03 10:42 Bingfeng Mei
2009-06-03 10:53 ` Richard Guenther
0 siblings, 1 reply; 6+ messages in thread
From: Bingfeng Mei @ 2009-06-03 10:42 UTC (permalink / raw)
To: gcc
Hello,
I noticed that the restrict doesn't work fully on 4.4.0 (used to work on
our port based on 4.3 branch). The problem is that tree optimizer can do a
lot of optimization regarding pointer, e.g., at -O3. The alias set property
is not propagated accordingly.
Is the following RTL expansion correct? Both read and write address are
converted to a restrict pointer, but the both mem rtx have the same alias set (2).
;; *(int * restrict) (D.1768 + 4) = *(int * restrict) (D.1770 + 4);
(insn 56 55 57 tst.c:7 (set (reg:SI 124)
(mem:SI (plus:SI (reg:SI 103 [ D.1770 ])
(const_int 4 [0x4])) [2 S4 A32])) -1 (nil))
(insn 57 56 0 tst.c:7 (set (mem:SI (plus:SI (reg:SI 104 [ D.1768 ])
(const_int 4 [0x4])) [2 S4 A32])
(reg:SI 124)) -1 (nil))
The alias set property is copied from tree node:
<indirect_ref 0xf7f09d40
type <integer_type 0xf7f122f4 int sizes-gimplified public SI
size <integer_cst 0xf7f0f9d8 constant 32>
unit size <integer_cst 0xf7f0f7c4 constant 4>
align 32 symtab 0 alias set 2 canonical type 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984 -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
pointer_to_this <pointer_type 0xf7f18798>>
arg 0 <nop_expr 0xf7fc7400
type <pointer_type 0xf7fa6870 type <integer_type 0xf7f122f4 int>
sizes-gimplified public unsigned restrict SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
arg 0 <plus_expr 0xf7fc95e8 type <integer_type 0xf7f12438 long unsigned int>
arg 0 <var_decl 0xf7fc4a6c D.1768>
arg 1 <integer_cst 0xf7fb7bec constant 4>
tst.c:7:5>
tst.c:7:5>
tst.c:7:5>
Is the RTL expansion wrong or the orginal tree node is constructed incorrectly?
Thanks,
Bingfeng Mei
Broadcom UK
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Restrict keyword doesn't work correctly in GCC 4.4
2009-06-03 10:42 Restrict keyword doesn't work correctly in GCC 4.4 Bingfeng Mei
@ 2009-06-03 10:53 ` Richard Guenther
2009-06-03 11:02 ` Bingfeng Mei
0 siblings, 1 reply; 6+ messages in thread
From: Richard Guenther @ 2009-06-03 10:53 UTC (permalink / raw)
To: Bingfeng Mei; +Cc: gcc
[-- Attachment #1: Type: text/plain, Size: 2335 bytes --]
On Wed, Jun 3, 2009 at 12:41 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> Hello,
> I noticed that the restrict doesn't work fully on 4.4.0 (used to work on
> our port based on 4.3 branch). The problem is that tree optimizer can do a
> lot of optimization regarding pointer, e.g., at -O3. The alias set property
> is not propagated accordingly.
>
> Is the following RTL expansion correct? Both read and write address are
> converted to a restrict pointer, but the both mem rtx have the same alias set (2).
>
> ;; *(int * restrict) (D.1768 + 4) = *(int * restrict) (D.1770 + 4);
restrict only works if there is a restrict qualified pointer decl in
your source.
I will re-implement restrict support completely for 4.5.
You can try the attached hack which might help (but also cause
weird effects ...).
Richard.
> (insn 56 55 57 tst.c:7 (set (reg:SI 124)
> (mem:SI (plus:SI (reg:SI 103 [ D.1770 ])
> (const_int 4 [0x4])) [2 S4 A32])) -1 (nil))
>
> (insn 57 56 0 tst.c:7 (set (mem:SI (plus:SI (reg:SI 104 [ D.1768 ])
> (const_int 4 [0x4])) [2 S4 A32])
> (reg:SI 124)) -1 (nil))
>
>
> The alias set property is copied from tree node:
> <indirect_ref 0xf7f09d40
> type <integer_type 0xf7f122f4 int sizes-gimplified public SI
> size <integer_cst 0xf7f0f9d8 constant 32>
> unit size <integer_cst 0xf7f0f7c4 constant 4>
> align 32 symtab 0 alias set 2 canonical type 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984 -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
> pointer_to_this <pointer_type 0xf7f18798>>
>
> arg 0 <nop_expr 0xf7fc7400
> type <pointer_type 0xf7fa6870 type <integer_type 0xf7f122f4 int>
> sizes-gimplified public unsigned restrict SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
> align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
>
> arg 0 <plus_expr 0xf7fc95e8 type <integer_type 0xf7f12438 long unsigned int>
> arg 0 <var_decl 0xf7fc4a6c D.1768>
> arg 1 <integer_cst 0xf7fb7bec constant 4>
> tst.c:7:5>
> tst.c:7:5>
> tst.c:7:5>
>
> Is the RTL expansion wrong or the orginal tree node is constructed incorrectly?
>
> Thanks,
> Bingfeng Mei
>
> Broadcom UK
>
[-- Attachment #2: p --]
[-- Type: application/octet-stream, Size: 2030 bytes --]
Index: gcc/alias.c
===================================================================
*** gcc/alias.c (revision 148119)
--- gcc/alias.c (working copy)
*************** get_deref_alias_set_1 (tree t)
*** 536,547 ****
{
tree decl = find_base_decl (t);
! if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
{
/* If we haven't computed the actual alias set, do it now. */
! if (DECL_POINTER_ALIAS_SET (decl) == -2)
{
! tree pointed_to_type = TREE_TYPE (TREE_TYPE (decl));
/* No two restricted pointers can point at the same thing.
However, a restricted pointer can point at the same thing
--- 536,550 ----
{
tree decl = find_base_decl (t);
! if (decl
! && POINTER_TYPE_P (TREE_TYPE (decl))
! && TYPE_RESTRICT (TREE_TYPE (decl)))
{
/* If we haven't computed the actual alias set, do it now. */
! if (DECL_POINTER_ALIAS_SET (decl) == -2
! || !DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
{
! tree pointed_to_type = TREE_TYPE (TREE_TYPE (t));
/* No two restricted pointers can point at the same thing.
However, a restricted pointer can point at the same thing
*************** get_deref_alias_set_1 (tree t)
*** 556,562 ****
if (pointed_to_alias_set == 0)
/* It's not legal to make a subset of alias set zero. */
DECL_POINTER_ALIAS_SET (decl) = 0;
! else if (AGGREGATE_TYPE_P (pointed_to_type))
/* For an aggregate, we must treat the restricted
pointer the same as an ordinary pointer. If we
were to make the type pointed to by the
--- 559,566 ----
if (pointed_to_alias_set == 0)
/* It's not legal to make a subset of alias set zero. */
DECL_POINTER_ALIAS_SET (decl) = 0;
! else if (AGGREGATE_TYPE_P (pointed_to_type)
! && TREE_CODE (pointed_to_type) != ARRAY_TYPE)
/* For an aggregate, we must treat the restricted
pointer the same as an ordinary pointer. If we
were to make the type pointed to by the
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Restrict keyword doesn't work correctly in GCC 4.4
2009-06-03 10:53 ` Richard Guenther
@ 2009-06-03 11:02 ` Bingfeng Mei
2009-06-03 14:09 ` Richard Guenther
0 siblings, 1 reply; 6+ messages in thread
From: Bingfeng Mei @ 2009-06-03 11:02 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc
Richard,
Yes, my original code does have restrict qualified decl:
void foo(int byte, char *a, char *b){
int * restrict dest = (int *)a;
int * restrict src = (int *)b;
for(int i = 0; i < byte/8; i++){
*dest++ = *src++;
}
}
The code I shown is produced by tree level compilation.
*(int * restrict) (D.1934 + 4) = *(int * restrict) (D.1936 + 4);
*(int * restrict) (D.1934 + 8) = *(int * restrict) (D.1936 + 8);
*(int * restrict) (D.1934 + 12) = *(int * restrict) (D.1936 + 12);
*(int * restrict) (D.1934 + 16) = *(int * restrict) (D.1936 + 16);
*(int * restrict) (D.1934 + 20) = *(int * restrict) (D.1936 + 20);
*(int * restrict) (D.1934 + 24) = *(int * restrict) (D.1936 + 24);
*(int * restrict) (D.1934 + 28) = *(int * restrict) (D.1936 + 28);
*(int * restrict) (D.1934 + 32) = *(int * restrict) (D.1936 + 32);
*(int * restrict) (D.1934 + 36) = *(int * restrict) (D.1936 + 36);
*(int * restrict) (D.1934 + 40) = *(int * restrict) (D.1936 + 40);
*(int * restrict) (D.1934 + 44) = *(int * restrict) (D.1936 + 44);
*(int * restrict) (D.1934 + 48) = *(int * restrict) (D.1936 + 48);
*(int * restrict) (D.1934 + 52) = *(int * restrict) (D.1936 + 52);
*(int * restrict) (D.1934 + 56) = *(int * restrict) (D.1936 + 56);
*(int * restrict) (D.1934 + 60) = *(int * restrict) (D.1936 + 60);
If we agree these tree statements still preserve the meaning of restrict,
it should be RTL expansion going wrong. Am I right?
- Bingfeng
> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> Sent: 03 June 2009 11:54
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: Restrict keyword doesn't work correctly in GCC 4.4
>
> On Wed, Jun 3, 2009 at 12:41 PM, Bingfeng Mei
> <bmei@broadcom.com> wrote:
> > Hello,
> > I noticed that the restrict doesn't work fully on 4.4.0
> (used to work on
> > our port based on 4.3 branch). The problem is that tree
> optimizer can do a
> > lot of optimization regarding pointer, e.g., at -O3. The
> alias set property
> > is not propagated accordingly.
> >
> > Is the following RTL expansion correct? Both read and write
> address are
> > converted to a restrict pointer, but the both mem rtx have
> the same alias set (2).
> >
> > ;; *(int * restrict) (D.1768 + 4) = *(int * restrict) (D.1770 + 4);
>
> restrict only works if there is a restrict qualified pointer decl in
> your source.
>
> I will re-implement restrict support completely for 4.5.
>
> You can try the attached hack which might help (but also cause
> weird effects ...).
>
> Richard.
>
> > (insn 56 55 57 tst.c:7 (set (reg:SI 124)
> > (mem:SI (plus:SI (reg:SI 103 [ D.1770 ])
> > (const_int 4 [0x4])) [2 S4 A32])) -1 (nil))
> >
> > (insn 57 56 0 tst.c:7 (set (mem:SI (plus:SI (reg:SI 104 [ D.1768 ])
> > (const_int 4 [0x4])) [2 S4 A32])
> > (reg:SI 124)) -1 (nil))
> >
> >
> > The alias set property is copied from tree node:
> > <indirect_ref 0xf7f09d40
> > type <integer_type 0xf7f122f4 int sizes-gimplified public SI
> > size <integer_cst 0xf7f0f9d8 constant 32>
> > unit size <integer_cst 0xf7f0f7c4 constant 4>
> > align 32 symtab 0 alias set 2 canonical type
> 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984
> -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
> > pointer_to_this <pointer_type 0xf7f18798>>
> >
> > arg 0 <nop_expr 0xf7fc7400
> > type <pointer_type 0xf7fa6870 type <integer_type
> 0xf7f122f4 int>
> > sizes-gimplified public unsigned restrict SI
> size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
> > align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
> >
> > arg 0 <plus_expr 0xf7fc95e8 type <integer_type
> 0xf7f12438 long unsigned int>
> > arg 0 <var_decl 0xf7fc4a6c D.1768>
> > arg 1 <integer_cst 0xf7fb7bec constant 4>
> > tst.c:7:5>
> > tst.c:7:5>
> > tst.c:7:5>
> >
> > Is the RTL expansion wrong or the orginal tree node is
> constructed incorrectly?
> >
> > Thanks,
> > Bingfeng Mei
> >
> > Broadcom UK
> >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Restrict keyword doesn't work correctly in GCC 4.4
2009-06-03 11:02 ` Bingfeng Mei
@ 2009-06-03 14:09 ` Richard Guenther
2009-06-03 15:35 ` Bingfeng Mei
0 siblings, 1 reply; 6+ messages in thread
From: Richard Guenther @ 2009-06-03 14:09 UTC (permalink / raw)
To: Bingfeng Mei; +Cc: gcc
On Wed, Jun 3, 2009 at 1:02 PM, Bingfeng Mei <bmei@broadcom.com> wrote:
> Richard,
> Yes, my original code does have restrict qualified decl:
>
> void foo(int byte, char *a, char *b){
> int * restrict dest = (int *)a;
> int * restrict src = (int *)b;
>
> for(int i = 0; i < byte/8; i++){
> *dest++ = *src++;
> }
> }
>
>
> The code I shown is produced by tree level compilation.
>
> *(int * restrict) (D.1934 + 4) = *(int * restrict) (D.1936 + 4);
> *(int * restrict) (D.1934 + 8) = *(int * restrict) (D.1936 + 8);
> *(int * restrict) (D.1934 + 12) = *(int * restrict) (D.1936 + 12);
> *(int * restrict) (D.1934 + 16) = *(int * restrict) (D.1936 + 16);
> *(int * restrict) (D.1934 + 20) = *(int * restrict) (D.1936 + 20);
> *(int * restrict) (D.1934 + 24) = *(int * restrict) (D.1936 + 24);
> *(int * restrict) (D.1934 + 28) = *(int * restrict) (D.1936 + 28);
> *(int * restrict) (D.1934 + 32) = *(int * restrict) (D.1936 + 32);
> *(int * restrict) (D.1934 + 36) = *(int * restrict) (D.1936 + 36);
> *(int * restrict) (D.1934 + 40) = *(int * restrict) (D.1936 + 40);
> *(int * restrict) (D.1934 + 44) = *(int * restrict) (D.1936 + 44);
> *(int * restrict) (D.1934 + 48) = *(int * restrict) (D.1936 + 48);
> *(int * restrict) (D.1934 + 52) = *(int * restrict) (D.1936 + 52);
> *(int * restrict) (D.1934 + 56) = *(int * restrict) (D.1936 + 56);
> *(int * restrict) (D.1934 + 60) = *(int * restrict) (D.1936 + 60);
>
> If we agree these tree statements still preserve the meaning of restrict,
> it should be RTL expansion going wrong. Am I right?
No, it is TER that removes the temporary that is required to make
restrict work. Try -fno-tree-ter or fixing TER to not TER
to-restrict-pointer conversions.
Richard.
>
> - Bingfeng
>
>
>> -----Original Message-----
>> From: Richard Guenther [mailto:richard.guenther@gmail.com]
>> Sent: 03 June 2009 11:54
>> To: Bingfeng Mei
>> Cc: gcc@gcc.gnu.org
>> Subject: Re: Restrict keyword doesn't work correctly in GCC 4.4
>>
>> On Wed, Jun 3, 2009 at 12:41 PM, Bingfeng Mei
>> <bmei@broadcom.com> wrote:
>> > Hello,
>> > I noticed that the restrict doesn't work fully on 4.4.0
>> (used to work on
>> > our port based on 4.3 branch). The problem is that tree
>> optimizer can do a
>> > lot of optimization regarding pointer, e.g., at -O3. The
>> alias set property
>> > is not propagated accordingly.
>> >
>> > Is the following RTL expansion correct? Both read and write
>> address are
>> > converted to a restrict pointer, but the both mem rtx have
>> the same alias set (2).
>> >
>> > ;; *(int * restrict) (D.1768 + 4) = *(int * restrict) (D.1770 + 4);
>>
>> restrict only works if there is a restrict qualified pointer decl in
>> your source.
>>
>> I will re-implement restrict support completely for 4.5.
>>
>> You can try the attached hack which might help (but also cause
>> weird effects ...).
>>
>> Richard.
>>
>> > (insn 56 55 57 tst.c:7 (set (reg:SI 124)
>> > (mem:SI (plus:SI (reg:SI 103 [ D.1770 ])
>> > (const_int 4 [0x4])) [2 S4 A32])) -1 (nil))
>> >
>> > (insn 57 56 0 tst.c:7 (set (mem:SI (plus:SI (reg:SI 104 [ D.1768 ])
>> > (const_int 4 [0x4])) [2 S4 A32])
>> > (reg:SI 124)) -1 (nil))
>> >
>> >
>> > The alias set property is copied from tree node:
>> > <indirect_ref 0xf7f09d40
>> > type <integer_type 0xf7f122f4 int sizes-gimplified public SI
>> > size <integer_cst 0xf7f0f9d8 constant 32>
>> > unit size <integer_cst 0xf7f0f7c4 constant 4>
>> > align 32 symtab 0 alias set 2 canonical type
>> 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984
>> -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
>> > pointer_to_this <pointer_type 0xf7f18798>>
>> >
>> > arg 0 <nop_expr 0xf7fc7400
>> > type <pointer_type 0xf7fa6870 type <integer_type
>> 0xf7f122f4 int>
>> > sizes-gimplified public unsigned restrict SI
>> size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
>> > align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
>> >
>> > arg 0 <plus_expr 0xf7fc95e8 type <integer_type
>> 0xf7f12438 long unsigned int>
>> > arg 0 <var_decl 0xf7fc4a6c D.1768>
>> > arg 1 <integer_cst 0xf7fb7bec constant 4>
>> > tst.c:7:5>
>> > tst.c:7:5>
>> > tst.c:7:5>
>> >
>> > Is the RTL expansion wrong or the orginal tree node is
>> constructed incorrectly?
>> >
>> > Thanks,
>> > Bingfeng Mei
>> >
>> > Broadcom UK
>> >
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Restrict keyword doesn't work correctly in GCC 4.4
2009-06-03 14:09 ` Richard Guenther
@ 2009-06-03 15:35 ` Bingfeng Mei
2009-06-03 15:46 ` Richard Guenther
0 siblings, 1 reply; 6+ messages in thread
From: Bingfeng Mei @ 2009-06-03 15:35 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc
Richard,
Thanks. I tried your patch and the -fno-tree-ter, and none works. The problem is that
decl = find_base_decl (TREE_OPERAND (inner, 0)); <--- Cannot find the base declaration, so decl = 0
if (decl <-- won't be checked
&& POINTER_TYPE_P (TREE_TYPE (decl))
&& TYPE_RESTRICT (TREE_TYPE (decl)))
The TREE_OPERAND (inner, 0) is:
<nop_expr 0xf7fc7400
type <pointer_type 0xf7fa6870
type <integer_type 0xf7f122f4 int sizes-gimplified public SI
size <integer_cst 0xf7f0f9d8 constant 32>
unit size <integer_cst 0xf7f0f7c4 constant 4>
align 32 symtab 0 alias set 2 canonical type 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984 -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
pointer_to_this <pointer_type 0xf7f18798>>
sizes-gimplified public unsigned restrict SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
arg 0 <plus_expr 0xf7fc95e8
type <integer_type 0xf7f12438 long unsigned int public unsigned SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
align 32 symtab 0 alias set -1 canonical type 0xf7f12438 precision 32 min <integer_cst 0xf7f0fa64 0> max <integer_cst 0xf7f0fa48 4294967295>>
arg 0 <var_decl 0xf7fc4a6c D.1768 type <integer_type 0xf7f12438 long unsigned int>
used unsigned ignored SI file tst.c line 1 col 6 size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
align 32 context <function_decl 0xf7fa7080 foo>
(reg:SI 104 [ D.1768 ])>
arg 1 <integer_cst 0xf7fb7bec constant 4>
tst.c:7:5>
tst.c:7:5>
I added the following code. It seems to work for my example and others. Not sure potential hazard with it.
...
else if(!decl
&& POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND(inner, 0)))
&& TYPE_RESTRICT (TREE_TYPE (TREE_OPERAND(inner, 0))))
{
return new_alias_set ();
}
....
Bingfeng
> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> Sent: 03 June 2009 15:10
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: Restrict keyword doesn't work correctly in GCC 4.4
>
> On Wed, Jun 3, 2009 at 1:02 PM, Bingfeng Mei
> <bmei@broadcom.com> wrote:
> > Richard,
> > Yes, my original code does have restrict qualified decl:
> >
> > void foo(int byte, char *a, char *b){
> > int * restrict dest = (int *)a;
> > int * restrict src = (int *)b;
> >
> > for(int i = 0; i < byte/8; i++){
> > *dest++ = *src++;
> > }
> > }
> >
> >
> > The code I shown is produced by tree level compilation.
> >
> > *(int * restrict) (D.1934 + 4) = *(int * restrict) (D.1936 + 4);
> > *(int * restrict) (D.1934 + 8) = *(int * restrict) (D.1936 + 8);
> > *(int * restrict) (D.1934 + 12) = *(int * restrict) (D.1936 + 12);
> > *(int * restrict) (D.1934 + 16) = *(int * restrict) (D.1936 + 16);
> > *(int * restrict) (D.1934 + 20) = *(int * restrict) (D.1936 + 20);
> > *(int * restrict) (D.1934 + 24) = *(int * restrict) (D.1936 + 24);
> > *(int * restrict) (D.1934 + 28) = *(int * restrict) (D.1936 + 28);
> > *(int * restrict) (D.1934 + 32) = *(int * restrict) (D.1936 + 32);
> > *(int * restrict) (D.1934 + 36) = *(int * restrict) (D.1936 + 36);
> > *(int * restrict) (D.1934 + 40) = *(int * restrict) (D.1936 + 40);
> > *(int * restrict) (D.1934 + 44) = *(int * restrict) (D.1936 + 44);
> > *(int * restrict) (D.1934 + 48) = *(int * restrict) (D.1936 + 48);
> > *(int * restrict) (D.1934 + 52) = *(int * restrict) (D.1936 + 52);
> > *(int * restrict) (D.1934 + 56) = *(int * restrict) (D.1936 + 56);
> > *(int * restrict) (D.1934 + 60) = *(int * restrict) (D.1936 + 60);
> >
> > If we agree these tree statements still preserve the
> meaning of restrict,
> > it should be RTL expansion going wrong. Am I right?
>
> No, it is TER that removes the temporary that is required to make
> restrict work. Try -fno-tree-ter or fixing TER to not TER
> to-restrict-pointer conversions.
>
> Richard.
>
> >
> > - Bingfeng
> >
> >
> >> -----Original Message-----
> >> From: Richard Guenther [mailto:richard.guenther@gmail.com]
> >> Sent: 03 June 2009 11:54
> >> To: Bingfeng Mei
> >> Cc: gcc@gcc.gnu.org
> >> Subject: Re: Restrict keyword doesn't work correctly in GCC 4.4
> >>
> >> On Wed, Jun 3, 2009 at 12:41 PM, Bingfeng Mei
> >> <bmei@broadcom.com> wrote:
> >> > Hello,
> >> > I noticed that the restrict doesn't work fully on 4.4.0
> >> (used to work on
> >> > our port based on 4.3 branch). The problem is that tree
> >> optimizer can do a
> >> > lot of optimization regarding pointer, e.g., at -O3. The
> >> alias set property
> >> > is not propagated accordingly.
> >> >
> >> > Is the following RTL expansion correct? Both read and write
> >> address are
> >> > converted to a restrict pointer, but the both mem rtx have
> >> the same alias set (2).
> >> >
> >> > ;; *(int * restrict) (D.1768 + 4) = *(int * restrict)
> (D.1770 + 4);
> >>
> >> restrict only works if there is a restrict qualified
> pointer decl in
> >> your source.
> >>
> >> I will re-implement restrict support completely for 4.5.
> >>
> >> You can try the attached hack which might help (but also cause
> >> weird effects ...).
> >>
> >> Richard.
> >>
> >> > (insn 56 55 57 tst.c:7 (set (reg:SI 124)
> >> > (mem:SI (plus:SI (reg:SI 103 [ D.1770 ])
> >> > (const_int 4 [0x4])) [2 S4 A32])) -1 (nil))
> >> >
> >> > (insn 57 56 0 tst.c:7 (set (mem:SI (plus:SI (reg:SI 104
> [ D.1768 ])
> >> > (const_int 4 [0x4])) [2 S4 A32])
> >> > (reg:SI 124)) -1 (nil))
> >> >
> >> >
> >> > The alias set property is copied from tree node:
> >> > <indirect_ref 0xf7f09d40
> >> > type <integer_type 0xf7f122f4 int sizes-gimplified public SI
> >> > size <integer_cst 0xf7f0f9d8 constant 32>
> >> > unit size <integer_cst 0xf7f0f7c4 constant 4>
> >> > align 32 symtab 0 alias set 2 canonical type
> >> 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984
> >> -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
> >> > pointer_to_this <pointer_type 0xf7f18798>>
> >> >
> >> > arg 0 <nop_expr 0xf7fc7400
> >> > type <pointer_type 0xf7fa6870 type <integer_type
> >> 0xf7f122f4 int>
> >> > sizes-gimplified public unsigned restrict SI
> >> size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst
> 0xf7f0f7c4 4>
> >> > align 32 symtab 0 alias set -1 canonical type
> 0xf7fa6870>
> >> >
> >> > arg 0 <plus_expr 0xf7fc95e8 type <integer_type
> >> 0xf7f12438 long unsigned int>
> >> > arg 0 <var_decl 0xf7fc4a6c D.1768>
> >> > arg 1 <integer_cst 0xf7fb7bec constant 4>
> >> > tst.c:7:5>
> >> > tst.c:7:5>
> >> > tst.c:7:5>
> >> >
> >> > Is the RTL expansion wrong or the orginal tree node is
> >> constructed incorrectly?
> >> >
> >> > Thanks,
> >> > Bingfeng Mei
> >> >
> >> > Broadcom UK
> >> >
> >>
> >
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Restrict keyword doesn't work correctly in GCC 4.4
2009-06-03 15:35 ` Bingfeng Mei
@ 2009-06-03 15:46 ` Richard Guenther
0 siblings, 0 replies; 6+ messages in thread
From: Richard Guenther @ 2009-06-03 15:46 UTC (permalink / raw)
To: Bingfeng Mei; +Cc: gcc
On Wed, Jun 3, 2009 at 5:34 PM, Bingfeng Mei
<bmei@broadcom.com> wrote:
> Richard,
> Thanks. I tried your patch and the -fno-tree-ter, and none works. The problem is that
>
> decl = find_base_decl (TREE_OPERAND (inner, 0)); <--- Cannot find the base declaration, so decl = 0
>
> if (decl <-- won't be checked
> && POINTER_TYPE_P (TREE_TYPE (decl))
> && TYPE_RESTRICT (TREE_TYPE (decl)))
>
>
> The TREE_OPERAND (inner, 0) is:
>
> <nop_expr 0xf7fc7400
> type <pointer_type 0xf7fa6870
> type <integer_type 0xf7f122f4 int sizes-gimplified public SI
> size <integer_cst 0xf7f0f9d8 constant 32>
> unit size <integer_cst 0xf7f0f7c4 constant 4>
> align 32 symtab 0 alias set 2 canonical type 0xf7f122f4 precision 32 min <integer_cst 0xf7f0f984 -2147483648> max <integer_cst 0xf7f0f9a0 2147483647>
> pointer_to_this <pointer_type 0xf7f18798>>
> sizes-gimplified public unsigned restrict SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
> align 32 symtab 0 alias set -1 canonical type 0xf7fa6870>
>
> arg 0 <plus_expr 0xf7fc95e8
> type <integer_type 0xf7f12438 long unsigned int public unsigned SI size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
> align 32 symtab 0 alias set -1 canonical type 0xf7f12438 precision 32 min <integer_cst 0xf7f0fa64 0> max <integer_cst 0xf7f0fa48 4294967295>>
>
> arg 0 <var_decl 0xf7fc4a6c D.1768 type <integer_type 0xf7f12438 long unsigned int>
> used unsigned ignored SI file tst.c line 1 col 6 size <integer_cst 0xf7f0f9d8 32> unit size <integer_cst 0xf7f0f7c4 4>
> align 32 context <function_decl 0xf7fa7080 foo>
> (reg:SI 104 [ D.1768 ])>
> arg 1 <integer_cst 0xf7fb7bec constant 4>
> tst.c:7:5>
> tst.c:7:5>
>
>
> I added the following code. It seems to work for my example and others. Not sure potential hazard with it.
> ...
> else if(!decl
> && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND(inner, 0)))
> && TYPE_RESTRICT (TREE_TYPE (TREE_OPERAND(inner, 0))))
> {
> return new_alias_set ();
> }
> ....
>
Ah, of course. As I said - restrict support is broken.
Richard.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-06-03 15:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-03 10:42 Restrict keyword doesn't work correctly in GCC 4.4 Bingfeng Mei
2009-06-03 10:53 ` Richard Guenther
2009-06-03 11:02 ` Bingfeng Mei
2009-06-03 14:09 ` Richard Guenther
2009-06-03 15:35 ` Bingfeng Mei
2009-06-03 15:46 ` Richard Guenther
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).