[LLVMdev] Optimization opportunity

Chris Lattner sabre at nondot.org
Fri Aug 27 00:20:34 PDT 2004


On Thu, 26 Aug 2004, Jeff Cohen wrote:

> There seems to be a disadvantage to the approach of allocating all
> locals on the stack using alloca.  Consider the following code:

There is nothing intrinsic in LLVM that prevents this from happening, we
just have not yet implemented 'stack packing'.

> We have two arrays, b and c, only one of which can exist at any given
> time.   Both g++ and Microsoft VC++ map both arrays to the same bytes in
> the stack frame.  LLVM doesn't.  As there isn't anything in the LLVM
> assembly code to mark the scope of locals, it will take some analysis to
> determine which locals can share the same memory locations.

Note that using scoping is really only a hack.  Those two arrays could
very well have been declared on entry to the function, and should be
optimized as such.  LLVM will eventually support this.

> Also, the store into the arrays generates two x86 machine instructions:
>
> 	lea %ECX, DWORD PTR [%ESP + 16]
> 	mov DWORD PTR [%ECX + <element offset>], %EAX
>
> These can be combined into a single instruction.  I'm tempted to work on
> this one myself :)

Yup, there are several things that can be improved in the X86 instruction
selector.  If you submit a patch to implement this, we would be happy to
apply it.  Continuing improvements in the code generator should eventually
make this kind of thing fall out automatically, but for now they must be
implemented manually.

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list