From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20036 invoked by alias); 8 Jul 2014 13:34:54 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 19581 invoked by uid 48); 8 Jul 2014 13:34:43 -0000 From: "vincenzo.innocente at cern dot ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/61747] New: min,max pattern not always properly optimized (for sse4 targets) Date: Tue, 08 Jul 2014 13:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincenzo.innocente at cern dot ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg00468.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61747 Bug ID: 61747 Summary: min,max pattern not always properly optimized (for sse4 targets) Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vincenzo.innocente at cern dot ch I was expecting gcc to substitute min/max instruction for (a>/ V1 vmax(V1 a, V1 b) { return (a>b) ? a : b; } template V1 vmin(V1 a, V1 b) { return (a Float bart(Float a) { constexpr Float zero{0.f}; constexpr Float it = zero+4.f; constexpr Float zt = zero-3.f; return vmin(vmax(a,zt),it); } float bar(float a) { return bart(a); } float32x4_t bar(float32x4_t a) { return bart(a); } I see c++ -std=c++11 -O2 -msse4.2 -s vmin.cc -S; cat vmin.s __Z3foofff: LFB2: maxss %xmm1, %xmm0 minss %xmm2, %xmm0 ret __Z3fooDv4_fS_S_: LFB3: maxps %xmm1, %xmm0 minps %xmm2, %xmm0 ret __Z3barf: LFB5: ucomiss LC3(%rip), %xmm0 jbe L12 minss LC2(%rip), %xmm0 ret .align 4,0x90 L12: movss LC3(%rip), %xmm0 ret __Z3barDv4_f: LFB6: movaps LC5(%rip), %xmm1 movaps %xmm0, %xmm2 movaps %xmm1, %xmm0 cmpltps %xmm2, %xmm0 blendvps %xmm0, %xmm2, %xmm1 movaps LC6(%rip), %xmm2 movaps %xmm1, %xmm0 cmpltps %xmm2, %xmm0 blendvps %xmm0, %xmm1, %xmm2 movaps %xmm2, %xmm0 ret ----------------- c++ -std=c++11 -O2 -msse4.2 -s vmin.cc -S -ffinite-math-only; cat vmin.s __Z3foofff: LFB2: maxss %xmm0, %xmm1 minss %xmm2, %xmm1 movaps %xmm1, %xmm0 ret __Z3fooDv4_fS_S_: LFB3: maxps %xmm1, %xmm0 movaps %xmm0, %xmm1 movaps %xmm2, %xmm0 cmpleps %xmm1, %xmm0 blendvps %xmm0, %xmm2, %xmm1 movaps %xmm1, %xmm0 ret __Z3barf: LFB5: maxss LC2(%rip), %xmm0 minss LC3(%rip), %xmm0 ret __Z3barDv4_f: LFB6: movaps LC5(%rip), %xmm1 movaps %xmm0, %xmm2 movaps %xmm1, %xmm0 cmpltps %xmm2, %xmm0 blendvps %xmm0, %xmm2, %xmm1 movaps LC6(%rip), %xmm2 movaps %xmm1, %xmm0 cmpltps %xmm2, %xmm0 blendvps %xmm0, %xmm1, %xmm2 movaps %xmm2, %xmm0 ret LFE6: -------------- eventually c++ -std=c++11 -Ofast -msse4.2 -s vmin.cc -S; cat vmin.s __Z3foofff: LFB2: maxss %xmm0, %xmm1 minss %xmm2, %xmm1 movaps %xmm1, %xmm0 ret __Z3fooDv4_fS_S_: LFB3: maxps %xmm0, %xmm1 minps %xmm2, %xmm1 movaps %xmm1, %xmm0 ret __Z3barf: LFB5: maxss LC2(%rip), %xmm0 minss LC3(%rip), %xmm0 ret __Z3barDv4_f: LFB6: maxps LC5(%rip), %xmm0 minps LC6(%rip), %xmm0 ret