From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9537B3938818; Tue, 11 Jan 2022 19:34:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9537B3938818 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103973] x86: 4-way comparison of floats/doubles with spaceship operator possibly suboptimal Date: Tue, 11 Jan 2022 19:34:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: 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: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2022 19:34:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103973 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #6 from Jakub Jelinek --- (In reply to Richard Biener from comment #5) > We are lowering this to >=20 > return =3D TARGET_EXPR !=3D SAVE_EXPR = ? > SAVE_EXPR < SAVE_EXPR ? less : SAVE_EXPR < SAVE_EXPR ? > greater : unordered : equivalent>>>; >=20 > I don't think we can elide the first ucomisd, but we should be able to CSE > the last (from the original quoted assembler), not sure if it ultimatively > results in better code though. Why we couldn't do that? It is true that GIMPLE starts with !=3D compariso= n that shouldn't raise exceptions if a or b is qNaN, but if one or both of the operands is qNaN, then they will compare unequal and < comparison that shou= ld raise exceptions if a or b is qNaN is done. So, it would be nice if we could at gimple_isel or expansion or later patte= rn recognize this and emit optimal code for it. C testcase: int foo (double a, double b) { if (a =3D=3D b) return 0; if (a < b) return -1; if (a > b) return 1; return 2; } We should have something like: comisd %xmm0, %xmm1 jp 1f movl $0, %eax jne 2f 3: ret 2: sbbl %eax, %eax andl $2, %eax subl $1, %eax ret 1: movl $2, %eax ret=