[LLVMdev] Poor floating point optimizations?

Duncan Sands baldrick at free.fr
Sun Nov 21 03:17:25 PST 2010

Hi Bob,

> For example expressions like "1+x+1+x+1+x+1+x" (basically adding a lot of
> constants and variables) are complied to a long series off<add>s both in IR
> and
> assembly code.
> Both GCC and MSVC generates C1*x +C2 (mov + mul + add).
> I am new to using LLVM. I am using Visual Studio 2008 on Windows, targeting
> 32-bit X86 code. I'm using LLVM as a library. I've
> added setOptLevel(CodeGenOpt::Aggressive) to the engine but with no effect.
> Please let me know if there are some optimization options/passes in LLVM that
> could optimize such example expressions as  "1+x+1+x+1+x+1+x".

the reassociate pass deliberately does not perform this kind of optimization
because it is not right to do so if strict floating point correctness is
required.  Probably it should do it if the user supplied an "unsafe math"
flag.  There's actually a plan to add an "unsafe math" flag to each fp
operation in the IR, so this setting can be per-operation, but it didn't
happen yet.



More information about the llvm-dev mailing list