g++ and aliasing bools
Paolo Carlini
pcarlini@unitus.it
Fri Jan 25 10:54:00 GMT 2002
Daniel Berlin wrote:
[...]
> The second is what we are trying to change, if it hasn't clicked by now.
> We want to say that everything besides simple c-like structs can alias
> anything, and simple c-like structs have the same aliasing properties as
> c structs.
>
> Simple c-like structs means classes and structs in C++ which have no base
> classes, and no virtual functions.
> If people agree that these are equivalent to c-structs (from an aliasing
> perspective, obviously there are some formal syntactical differences), then we can.
> If they don't, then apparently someone else needs to take the time to
> prove it formally, at which point we can add 6 lines of code (or
> whatever, it depends on whether someone can point out any small
> difference in aliasing properties that need to be accounted for) to g++ to
> do it.
>
> There is no "problem" as aliasing for C++ works today, because it doesn't
> do anything for things that aren't in reality, C.
>
> Therein lies the other half of why i don't think the above needs to be
> proven formally, if they are agreed to be equivalent
>
> Already, for non-aggregate types, the routine for C++ TBAA simply calls
> the c routine.
>
> The whole code is literally:
>
> cxx_get_alias_set ()
> {
> if (AGGREGATE_TYPE)
> return 0;
> return c_get_alias_set();
> }
>
> The above suggestion is simply saying "AGGREGATE_TYPE is way too
> conservative, we only need to return 0 for those things that have C++
> specific features that may affect aliasing, like virtual functions, or
> inheritance", so let's change it to:
>
> cxx_get_alias_set ()
> {
> if (AGGREGATE_TYPE && HAS_BASECLASSES && HAS_VIRTUALS)
> return 0;
> return c_get_alias_set();
> }
[...]
>From my, utterly naive point of view, this looks like an incredibly appealing
proposal!!!!
Consider my beloved testcase (distilled from Haney Speed), which is currently
optimized *very* bad by g++:
/////////////////
class RealMatrix {
public:
float &index(int i, int j)
{
return d[i - 1 + n[0] * (j - 1)];
}
float index(int i, int j) const
{
return d[i - 1 + n[0] * (j - 1)];
}
int dim(int i) const { return n[i - 1]; }
private:
float *d;
int n[4];
};
void rmatMul(RealMatrix &t, const RealMatrix &a, const RealMatrix &b)
{
const int M = a.dim(1), N = b.dim(2), K = b.dim(1);
for (int j = 1; j <= N; j++)
{
for (int k = 1; k <= K; k++)
{
float temp = b.index(k, j);
if (temp != 0.0)
{
for (int i = 1; i <= M; i++)
t.index(i, j) += temp * a.index(i, k);
}
}
}
}
///////////////////////
Honestly, I cannot imagine why the bulk of the C aliasing analysis machinery could not
be used for it!!!!
Cheers,
Paolo.
More information about the Gcc
mailing list