LLVM Struct Return Optimization

拟墨画扇 提交于 2019-12-22 04:07:24

问题


I'm wondering why LLVM fails to optimize the following IR code (using the PassManagerBuilder with optimisation set to '3', and also using LLVM's 'opt' tool):

%GenericStruct = type { i32 }

define void @makeGenericStructOuter(%GenericStruct* noalias nocapture sret) {
entry:
  %1 = alloca %GenericStruct
  call void @makeGenericStructInner(%GenericStruct* %1)
  %2 = load %GenericStruct* %1
  store %GenericStruct %2, %GenericStruct* %0
  ret void
}

declare void @makeGenericStructInner(%GenericStruct* noalias nocapture sret)

The expected code is:

%GenericStruct = type { i32 }

define void @makeGenericStructOuter(%GenericStruct* noalias nocapture sret) {
entry:
  call void @makeGenericStructInner(%GenericStruct* %0)
  ret void
}

declare void @makeGenericStructInner(%GenericStruct* noalias nocapture sret)

Are there simply no optimizations currently available to handle this case? Or am I failing to produce (this code is generated from a front-end I'm developing) the right IR that would allow optimization?

Before it's suggested, I can't produce code that returns by value since these functions must be callable from other modules/libraries that don't know the size or contents of 'GenericStruct' (and they would locally declare 'TestClass' as 'struct opaque').


回答1:


If you belive that optimization should take place, report a bug in LLVM Bug Tracker. LLVM developers are usually very happy and interested when reporting optimization opportunities missed.



来源:https://stackoverflow.com/questions/13039531/llvm-struct-return-optimization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!