[cpp-threads] modes, interlude

Peter Dimov pdimov at mmltd.net
Tue May 10 11:44:03 BST 2005


Alexander Terekhov wrote:

> But do you really still have some problems with dd* stuff?

dd* is very hard to specify.

    x = atomic_load[_ddacq]( &addr );
    y = a[ x ];

Is a[x] data-dependent? It depends on the set of possible values that the 
load can return and the type of x. If x is bool, for example, it's very 
likely not data-dependent; the compiler can just preload a[0] and a[1] or 
reuse them. In the general case when using global analysis, there is no way 
to tell whether a[x] is dependent just by looking at this code fragment.

The compiler can also turn data dependency into control dependency by using 
its own variation of value prediction. Let's assume that the previous line 
was

    r = a[0];

The compiler may now use

if( x == 0 )
{
    y = r;
}
else
{
    y = a[x];
}

and break the data dependency. We could disallow this optimization when 
ddacq is present, but to do that, we need to define whether an expression is 
data-dependent. :-)





More information about the cpp-threads mailing list