[LLVMdev] why gvn does not work for global variables
Xiangyang Guo
xguo6 at ncsu.edu
Sat Jul 25 17:14:40 PDT 2015
Hi, All,
Suppose I have a very simple code like this and variable 'a' is a global
variable:
***************************************************************************
*double ** a;*
*int main(){*
* a[5][10] = 0.1;*
* a[5][20] = 0.5;*
* return 0;*
*}*
***************************************************************************
Then I can get the IR without any optimization like this:
***************************************************************************
*@a = global double** null, align 8*
*; Function Attrs: nounwind uwtable*
*define i32 @main() #0 {*
* %1 = alloca i32, align 4*
* store i32 0, i32* %1*
* %2 = load double*** @a, align 8*
* %3 = getelementptr inbounds double** %2, i64 5*
* %4 = load double** %3, align 8*
* %5 = getelementptr inbounds double* %4, i64 10*
* store double 1.000000e-01, double* %5, align 8*
* %6 = load double*** @a, align 8*
* %7 = getelementptr inbounds double** %6, i64 5*
* %8 = load double** %7, align 8*
* %9 = getelementptr inbounds double* %8, i64 20*
* store double 5.000000e-01, double* %9, align 8*
* ret i32 0*
*}*
***************************************************************************
I hope GVN can get rid of redundant 'load' and 'getelementptr' instructions
such as '*%2 = load double*** @a, align 8*' and '*%6 = load double*** @a,
align 8*'. So I use 'opt input.ll -basicaa -gvn -S -o output.ll ' , I still
get :
***************************************************************************
* %2 = load double*** @a, align 8*
* %3 = getelementptr inbounds double** %2, i64 5*
* %4 = load double** %3, align 8*
* %5 = getelementptr inbounds double* %4, i64 10*
* store double 1.000000e-01, double* %5, align 8*
* %6 = load double*** @a, align 8*
* %7 = getelementptr inbounds double** %6, i64 5*
* %8 = load double** %7, align 8*
* %9 = getelementptr inbounds double* %8, i64 20*
* store double 5.000000e-01, double* %9, align 8*
***************************************************************************
It seems GVN doesn't work. Then I use '-aa-eval', it seems LLVM thinks that
is "*may alias*". But '%2' and '%6' are alias, right?
***************************************************************************
*===== Alias Analysis Evaluator Report =====*
* 45 Total Alias Queries Performed*
* 13 no alias responses (28.8%)*
* 32 may alias responses (71.1%)*
* 0 partial alias responses (0.0%)*
* 0 must alias responses (0.0%)*
* Alias Analysis Evaluator Pointer Alias Summary: 28%/71%/0%/0%*
* Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!*
***************************************************************************
Can anyone help me to use GVN in this situation? Thanks
Regards,
Xiangyang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150725/cee7c52e/attachment.html>
More information about the llvm-dev
mailing list