[LLVMdev] A question about GetElementPtr common subexpression elimination/loop invariant code motion

Chris Lattner sabre at nondot.org
Mon Jan 29 11:54:11 PST 2007


On Mon, 29 Jan 2007, Gil Dogon wrote:
> Now the problem with this code , is that the calculation of the address
> mat[i][j] which is done by the (two) getelementptr instructions
> is quite expensive (involving at least two multiplications and one
> addition) hence it actualy should have been moved out of the inner loop.

Right.

> and not twice. Anyway this is just a syptom of a general
> phenomenon in which it seems my LLVM assumes that getelemenptrs are
> atomic and it does not try to do any optimization on
> them.

LLVM assumes that the code generator will handle this optimization when 
the getelementptr's are lowered into integer arithmetic.  Many things can 
only be optimized after lowering in the code generator, and LICM of simple 
integer arithmetic is one trivial example.  The goal of the LLVM-level 
optimizers is to handle the heavier lifting stuff, such as code 
restructuring, loop optimization, memory optimization, etc.

-Chris

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



More information about the llvm-dev mailing list