From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8B75F3830B49; Tue, 22 Aug 2023 13:30:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B75F3830B49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692711006; bh=74G6i3vmPI3t94WyvRGHyV5xQp8Z5OpxqGQA39/2rao=; h=From:To:Subject:Date:From; b=s3R/739N0vmLVlpwjPsDM9uFsyscLK5BWnfJyLtCmSTNmlCq6ALJrpqN/TGsFBy3t Zfpng7jFvNHSL6We5vNZ3KTJ6E1wkKyG4yodZCy6hZxCqxKuy3rESvpxOXyNjvgh45 Tfo1OozaAkn8DBl4CkJlzPlI+3+hvfwjx6ty7MQI= From: "pavel.morozkin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/111101] New: -finline-small-functions may invert FP arguments breaking FP bit accuracy in case of NaNs Date: Tue, 22 Aug 2023 13:30:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pavel.morozkin at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111101 Bug ID: 111101 Summary: -finline-small-functions may invert FP arguments breaking FP bit accuracy in case of NaNs Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pavel.morozkin at gmail dot com Target Milestone: --- Notes: 1. This may not be a bug. 2. This may be a duplicate. 3. I don't have MRE. Brief: -finline-small-functions may invert FP arguments breaking FP bit accuracy=20 in case of NaNs Demo: $ gcc t1.c -O1 -std=3Dc11 && ./a r nan 7fe5ed65 r_ref nan 7fe5ed65 $ gcc t1.c -O1 -std=3Dc11 -finline-small-functions && ./a r -nan fffffffe r_ref nan 7fe5ed65 Description: In my code I add two FP values (represented in "raw hex"): 0x7fa5ed65 (sNaN) with 0xfffffffe (qNaN). x86_64 instruction addss returns 0x7fe5ed65 (sNaN). However, under -finline-small-functions gcc, I guess, rewrites A+B to B+A, resulting in 0xfffffffe (qNaN), which breaks FP bit accuracy. I examined generated assembly code: -O1: add(x, y) x =3D> ecx =3D> ebp =3D> xmm0 y =3D> edx =3D> edi =3D> xmm1 addss xmm1, xmm0 (at&t syntax) -O1 -finline-small-functions: add(x, y) x =3D> ecx =3D> esi =3D> xmm1 y =3D> edx =3D> ebx =3D> xmm0 addss xmm1, xmm0 (at&t syntax) Here we see that in case of -finline-small-functions x and y are inverted. Notes: 1. Some software may rely on FP bit accuracy in case of NaNs (NaN boxing, etc.). 2. I'm not sure which "Component:" to select: rtl-optimization or tree-optimization.=