yonghong-song added a comment.

I checked EmitAutoVarAlloca(). It emits the llvm.stacksave() due to

  // If the type is variably-modified, emit all the VLA sizes for it.
  if (Ty->isVariablyModifiedType())
    EmitVariablyModifiedType(Ty);

Here, in order not to generate llvm.stacksave(), we need to evaluate the array 
size expression for `Ty`.
But it is probably not a good idea to re-evaluate `Ty` during code generation 
phase. If we really want to evaluate, we should evaluate earlier during 
semantic analysis phase like this patch.

Another solution is to implement pruning llvm.stacksave/stackrestore in 
backend. Currently InstCombine phase tries to remove some adjacent stacksave() 
and stackrestore() instrinsics. We could try to enhance InstCombine to handle 
more complicated cases, or considering this may be just a BPF use case (which 
doesn't support dynamic memory allocation), we can implement a bpf backend IR 
phase to remove it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107882/new/

https://reviews.llvm.org/D107882

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to