[LLVMdev] Pointer aliasing
Brent Walker
brenthwalker at gmail.com
Sun Jan 22 18:31:43 PST 2012
Hi LLVMers,
I would like to ask a question regarding aliasing. Suppose I have the
following program:
double f(double** p )
{
double a,b,c;
double * x = &a;
double * y = &b;
double * z = &c;
*x = 1;
*y = *x + 2;
*z = *x + 3;
return *x+*y+*z;
}
LLVM can tell that the three pointers do not alias each other so can
perform the constant folding at compile time.
define double @f(double** nocapture %p) nounwind uwtable readnone {
ret double 8.000000e+00
}
Now consider the function below. I know (in my particluar case) that
the pointers in the p array do not alias each other. I tried to
communicate this information to llvm/clang via the __restrict__
qualifier but it does not seem to have an effect. Can you please
suggest what is wrong. How can I achieve what I want?
double f(double** p )
{
double *__restrict__ x = p[0];
double *__restrict__ y = p[1];
double *__restrict__ z = p[2];
*x = 1;
*y = *x + 2;
*z = *x + 3;
return *x+*y+*z;
}
define double @f(double** nocapture %p) nounwind uwtable {
%1 = load double** %p, align 8, !tbaa !0
%2 = getelementptr inbounds double** %p, i64 1
%3 = load double** %2, align 8, !tbaa !0
%4 = getelementptr inbounds double** %p, i64 2
%5 = load double** %4, align 8, !tbaa !0
store double 1.000000e+00, double* %1, align 8, !tbaa !3
store double 3.000000e+00, double* %3, align 8, !tbaa !3
%6 = load double* %1, align 8, !tbaa !3
%7 = fadd double %6, 3.000000e+00
store double %7, double* %5, align 8, !tbaa !3
%8 = load double* %1, align 8, !tbaa !3
%9 = load double* %3, align 8, !tbaa !3
%10 = fadd double %8, %9
%11 = fadd double %10, %7
ret double %11
}
!0 = metadata !{metadata !"any pointer", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
!3 = metadata !{metadata !"double", metadata !1}
Thank you for any help.
Brent
More information about the llvm-dev
mailing list