This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Incorrect bitfield aliasing with Tree SSA
> Because it wouldn't be pruning it if the alias sets conflicted!
Well, just look at the first RTL dump for:
struct S { int i; };
int f (struct S *s, int *p)
{
s->i = 0;
*p = 1;
return s->i;
}
and
package P is
type S is record
i : Integer;
end record;
type SP is access all S;
type IP is access all Integer;
function f (s : SP; p : IP) return Integer;
end P;
package body P is
function f (s : SP; p : IP) return Integer is
begin
s.i := 0;
p.all := 1;
return s.i;
end;
end P;
compiled at -O2 -gnatp -fno-tree-dominator-opts -fno-tree-store-ccp.
For the C testcase:
;; s->i = 0
(insn 7 6 0 t.c:5 (set (mem/s:SI (reg/v/f:DI 59 [ s ]) [3 <variable>.i+0 S4
A32])
(const_int 0 [0x0])) -1 (nil))
;; *p = 1
(insn 8 7 0 t.c:6 (set (mem:SI (reg/v/f:DI 60 [ p ]) [3 S4 A32])
(const_int 1 [0x1])) -1 (nil))
;; return s->i
(insn 9 8 10 t.c:6 (set (reg:SI 62)
(mem/s:SI (reg/v/f:DI 59 [ s ]) [3 <variable>.i+0 S4 A32])) -1 (nil))
i.e. everything is accessed with the alias set of 'int'.
For the Ada testcase:
;; s->i = 0
(insn 7 6 0 p.adb:5 (set (mem/s/j:SI (reg/v/f:DI 59 [ s ]) [4 <variable>.i+0
S4 A32])
(const_int 0 [0x0])) -1 (nil))
;; *p = 1
(insn 8 7 0 p.adb:6 (set (mem:SI (reg/v/f:DI 60 [ p ]) [2 S4 A32])
(const_int 1 [0x1])) -1 (nil))
;; return s->i
(insn 9 8 10 p.adb:6 (set (reg:SI 62)
(mem/s/j:SI (reg/v/f:DI 59 [ s ]) [4 <variable>.i+0 S4 A32])) -1
(nil))
i.e. s->i is accessed with the alias set of 'S'.
Now put 'aliased' on the field
type S is record
i : aliased Integer;
end record;
and you get:
;; s->i = 0
(insn 7 6 0 p.adb:5 (set (mem/s:SI (reg/v/f:DI 59 [ s ]) [2 <variable>.i+0 S4
A32])
(const_int 0 [0x0])) -1 (nil))
;; *p = 1
(insn 8 7 0 p.adb:6 (set (mem:SI (reg/v/f:DI 60 [ p ]) [2 S4 A32])
(const_int 1 [0x1])) -1 (nil))
;; return s->i
(insn 9 8 10 p.adb:6 (set (reg:SI 62)
(mem/s:SI (reg/v/f:DI 59 [ s ]) [2 <variable>.i+0 S4 A32])) -1 (nil))
like in C. The discrepancy purely stems from DECL_NONADDRESSABLE_P.
> > I didn't invent it either, but everything is more or less documented.
>
> No, not really.
Yes, it is, that's how I've understood how this stuff works.
--
Eric Botcazou