On Fri, Mar 28, 2014 at 03:03:11PM +0000, Andrew Haley wrote:
> On 03/28/2014 02:48 PM, Hannes Frederic Sowa wrote:
> > On Fri, Mar 28, 2014 at 01:15:39PM +0000, Andrew Haley wrote:
> >> On 03/28/2014 10:46 AM, Hannes Frederic Sowa wrote:
> >>> On Fri, Mar 28, 2014 at 09:41:41AM +0000, Andrew Haley wrote:
> >>>> On 03/28/2014 09:30 AM, Hannes Frederic Sowa wrote:
> >>>>> On Fri, Mar 28, 2014 at 09:10:11AM +0000, Andrew Haley wrote:
> >>>>>> On 03/28/2014 06:20 AM, dw wrote:
> >
> >>>> What is true here is that all registers used to cache variables that
> >>>> are reachable from pointers in the program are flushed. Anything that
> >>>> is statically allocated is reachable, as is anything dynamically
> >>>> allocated by malloc; auto variables are not reachable unless their
> >>>> address is taken.
> >>>
> >>> One would have to go into detail of various optimizations which could
> >>> remove the address taking
> >>
> >> One would not: any such optimization would be incorrect. Any memory
> >> reachable from an inline asm statement with a memory clobber must
> >> be flushed to memory.
> >
> > If I extend your example with an additional pointer and take the address of
> > s
> > it still doesn't allocate s in memory and as such cannot flush out the
> > register content, which is perfectly legal. The pointer is completley
> > eliminated (this is an extreme example).
> >
> > int sum(int a[], int l) {
> > int i;
> > int s = 0;
> > int *sp = &s;
> > for (i = 0; i < l; i++) {
> > asm volatile("nop # Nothing at all":::"memory");
> > *sp += a[i];
> > }
> > return s;
> > }
>
> But that's not reachable from the asm. Reachability is key here. The
> address of s is taken, but not used; GCC knows that it is not
> reachable.
>
> >>> e.g. IMHO the last sentence of the paragraph already
> >>> deals with this.
> >>
> >> Which last sentence of what paragraph?
> >
> > This one:
> >
> > | For performance reasons, some variables only exist in registers
> > | and never get written to memory. The "memory" clobber does not
> > | force these values to get written to memory.
>
> Except when it does; this is why the technical language has to be
> *precise*.
>
> The memory clobber will force all reachable variables into memory: it
> must.
>
> If we're going to avoid precise technical terms like "reachable" we
> have to find some other way of saying this, or not mention is at all.
> We must not say things that are misleading.
I guess I was confused with the term reachability, because I considered
stack values reachable regarding the inline assembler block, too.
Can one call that "symbolic reachability"? It would be great if the new
documentation could explain that, but I guess I am not the right person to
propose such a paragraph.
Bye,
Hannes