GCC Status Report (2004-03-09)

Jakub Jelinek jakub@redhat.com
Fri Apr 9 20:06:00 GMT 2004


On Thu, Apr 01, 2004 at 09:53:25AM -0500, Richard Kenner wrote:
>     Clearly we don't guarantee that some memory location which is written
>     by /u is never actually read with non-/u MEM.  At which point all /u stores
>     are potential bugs.
> 
> Something's very wrong here.  /u stores are supposed to conflict with
> *all* stores, both /u and not /u.  If somebody changed that, it will
> cause *lots* of problems, such as this!

On 20040401-1.c (test2) stock gcc-3_4-branch it is clearly cse:
grep -A2 +8 test2.c.05.null
(insn 11 10 12 0 (set (mem/s/u:HI (reg/f:DI 341) [2 X+8 S2 A64])
        (const_int 0 [0x0])) -1 (nil)
    (nil))
--
(insn 29 28 33 0 (set (mem/s/u:QI (reg/f:DI 353) [0 X+8 S1 A64])
        (reg:QI 354)) -1 (nil)
    (nil))
--
(insn 40 39 41 0 (set (reg:HI 362 [ X+8 ])
        (mem/s:HI (reg/f:DI 361) [2 X+8 S2 A64])) -1 (nil)
    (nil))

(insn 41 40 44 0 (set (mem/s:HI (reg/f:DI 359) [3 buffer+8 S2 A64])
        (reg:HI 362 [ X+8 ])) -1 (nil)
    (nil))
...

grep -A2 +8 t.c.06.cse
(insn 11 10 12 0 (set (mem/s/u:HI (reg/f:DI 341) [2 X+8 S2 A64])
        (const_int 0 [0x0])) 3 {*movhi_internal} (nil)
    (nil))
--
(insn 29 28 33 0 (set (mem/s/u:QI (reg/f:DI 341) [0 X+8 S1 A64])
        (reg:QI 354)) 2 {*movqi_internal} (nil)
    (nil))
--
(insn 41 37 45 0 (set (mem/s:HI (reg/f:DI 359) [3 buffer+8 S2 A64])
        (const_int 0 [0x0])) 3 {*movhi_internal} (nil)
    (nil))
...

so supposedly if we eliminate /u double-stores (which weren't completely
eliminated by optimization/8634 hack) and if writing with /u and
reading with non-/u from the same location is safe we should be done.

If we go with initialization in a temporary object, then copy, did you
mean to do the copy into mem/u:BLK (whenever there is at least one
const field) or copy field by field, always with the appropriate /u
flag?

FYI: One example where mixed non-const/const big aggregate is used in
real-world is regex in GLIBC.  On 64-bit arches there is a 192 byte
long structure with 8 byte field const in the middle, initialized with
  re_match_context_t mctx = { .dfa = dfa };
The const is quite important, it improves most of the regexec.c functions
a lot.  But for regexec.c it would be certainly better to drop the
/u flag in the single one function which initializes this object
than to do additional 192 bytes copy.

	Jakub



More information about the Gcc-patches mailing list