FoldGEP only for Constant

Hi,

Why FoldGEP is performed only for Constants ?

Could we perform this also for alloca ?

Thanks

What exactly do you want to transform to what?

Right now llvm will generate:

%0 = alloca [4 x float]
%1 = getelementptr [4 x float], ptr addrspace(0) %0, i32 0
%2 = load float, ptr addrspace(0) %1, align 4

I would expect to see something like this:

%0 = alloca [4 x float]
%1 = load float, ptr addrspace(0) %0, align 4

Is it something illegal ?

IRBuilder supports multiple different “folders” that allow simplifying operations before instructions get generated for them. By default it uses ConstantFolder, which performs data-layout independent folding. The other standard folders are NoFolder (does the obvious), TargetFolder (performs data-layout dependent folding) and InstSimplifyFolder.

If you specify the InstSimplifyFolder, then the simplification you suggest should get applied.

Most places will stick to just ConstantFolder/TargetFolder and leave everything else to InstCombine though.

1 Like

If you specify the InstSimplifyFolder, then the simplification you suggest should get applied.

This is what I was looking for. Thanks for the help !