[llvm-dev] Optimizing functions using logical operators

Cranmer, Joshua via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 26 12:50:19 PDT 2019


> -----Original Message-----
> From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Stéphane
> Letz via llvm-dev
> Sent: Thursday, September 26, 2019 13:38
> To: via llvm-dev <llvm-dev at lists.llvm.org>
> Subject: [llvm-dev] Optimizing functions using logical operators
> 
> Hi,
> 
> I’m looking at what the LLVM compilation chain does to optimize the
> following functions using logical operators. The one using integer type (t1 and
> t3) are optimized, but not the ones using float type (t2 and t4), even when
> using -O3 or -Ofast.  Why is that ?
> 
> Thera are those kind of optimizations done in the LLVM source code?

The main source for these sorts of peephole optimizations at the LLVM IR level is in instcombine, spread out over several files in lib/Transforms/InstCombine. Specifically, the relevant patterns are all in InstCombineCompares.

The floating point code is not optimized because there are no patterns specified that come close to covering these instructions. There are probably two main reasons for this. First, floating point optimizations are more dangerous to do floating point arithmetic not following normal rules of associativity (so it requires a lot more care to make sure that it is correct). Second, these optimizations probably don't kick in very often in real code. I've noticed that none of the major compilers optimize these expressions.


More information about the llvm-dev mailing list