mem2reg not working in this case?

I can’t get the alloca in attached function to be promoted to (a) register(s).

I try with

opt -mem2reg < module_eval0.ll

but the output is unchanged. Using LLVM 13 release.

Can anyone see why it’s not working? Is this too complicated for mem2reg? The alloca is moved to the beginning… is this the problem?


module_eval0.ll (2.72 KB)

While this doesn't answer your question it might still solve your problem:

opt -sroa < module_eval0.ll

~ Johannes

Mem2reg only supports trivial loads and stores of the alloca. These noop GEP operations are blocking it:

%14 = getelementptr float, float* %0, i32 0

I’d recommend changing your frontend to not generate them.