[llvm-dev] Optimizing functions using logical operators

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 26 12:56:58 PDT 2019


gcc does optimize t2 to just a compare under -Ofast. But clang does not.

~Craig


On Thu, Sep 26, 2019 at 12:50 PM Cranmer, Joshua via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> > -----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.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190926/7238adb4/attachment.html>


More information about the llvm-dev mailing list