Hi,
I would like to eliminate all the load instructions and replace their uses
with the stored values in the following program. The stores and loads are
in the same basic block.
Is there an optimization pass in LLVM 3.0 that can do this?
define void @testFunc() {
entry:
%sVal = alloca %sTy
%f1 = getelementptr %sTy* %sVal, i32 0, i32 0
store i32 789, i32* %f1
%f2 = getelementptr %sTy* %sVal, i32 0, i32 1
store double 3.523460e+01, double* %f2
%f3 = getelementptr %sTy* %sVal, i32 0, i32 2
store double 0x41CD6F34588147AE, double* %f3
%f1a = getelementptr %sTy* %sVal, i32 0, i32 0
%f1v = load i32* %f1a
%f2a = getelementptr %sTy* %sVal, i32 0, i32 1
%f2v = load double* %f2a
%f3a = getelementptr %sTy* %sVal, i32 0, i32 2
%f3v = load double* %f3a
call void @print(i32 %f1v, double %f2v, double %f3v)
ret void
}
The GVN pass is able to eliminate %f1a, %f2a and %f3a but not any of the
loads. Here is the result of running the GVN pass:
define void @testFunc() {
entry:
%sVal = alloca %sTy
%f1 = getelementptr %sTy* %sVal, i32 0, i32 0
store i32 789, i32* %f1
%f2 = getelementptr %sTy* %sVal, i32 0, i32 1
store double 3.523460e+01, double* %f2
%f3 = getelementptr %sTy* %sVal, i32 0, i32 2
store double 0x41CD6F34588147AE, double* %f3
%f1v = load i32* %f1
%f2v = load double* %f2
%f3v = load double* %f3
call void @print(i32 %f1v, double %f2v, double %f3v)
ret void
}
The instruction combining pass eliminates the last load (%f3v) but not the
other two. I do not know why the pass does not eliminate the other two
loads (%f2v and %f3v). The result of running the pass is:
define void @testFunc() {
entry:
%sVal = alloca %sTy
%f1 = getelementptr %sTy* %sVal, i32 0, i32 0
store i32 789, i32* %f1
%f2 = getelementptr %sTy* %sVal, i32 0, i32 1
store double 3.523460e+01, double* %f2
%f3 = getelementptr %sTy* %sVal, i32 0, i32 2
store double 0x41CD6F34588147AE, double* %f3
%f1a = getelementptr %sTy* %sVal, i32 0, i32 0
%f1v = load i32* %f1a
%f2a = getelementptr %sTy* %sVal, i32 0, i32 1
%f2v = load double* %f2a
call void @print(i32 %f1v, double %f2v, double 0x41CD6F34588147AE)
ret void
}
I will appreciate any help on this.
Thank you.
Best regards,
Nurudeen.