9

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').

Stephen Cross
  • 1,003
  • 1
  • 8
  • 19
  • Didn't you forget a `%0` in `@makeGenericStructOuter` signature? – arrowd Oct 27 '12 at 07:01
  • 2
    I also wonder about this, because it would improve the quality of Emscripten-generated code in several cases. Here is the commit where a relevant LLVM optimization pass was removed: http://llvm.org/viewvc/llvm-project?view=revision&revision=129314 – Chad Austin Aug 02 '13 at 06:59

1 Answers1

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.

Paweł Bylica
  • 3,780
  • 1
  • 31
  • 44