<div dir="ltr">gcc does optimize t2 to just a compare under -Ofast. But clang does not.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 26, 2019 at 12:50 PM Cranmer, Joshua via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> -----Original Message-----<br>
> From: llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> On Behalf Of Stéphane<br>
> Letz via llvm-dev<br>
> Sent: Thursday, September 26, 2019 13:38<br>
> To: via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
> Subject: [llvm-dev] Optimizing functions using logical operators<br>
> <br>
> Hi,<br>
> <br>
> I’m looking at what the LLVM compilation chain does to optimize the<br>
> following functions using logical operators. The one using integer type (t1 and<br>
> t3) are optimized, but not the ones using float type (t2 and t4), even when<br>
> using -O3 or -Ofast.  Why is that ?<br>
> <br>
> Thera are those kind of optimizations done in the LLVM source code?<br>
<br>
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.<br>
<br>
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.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>