From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CCD183858402; Mon, 25 Oct 2021 13:43:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCD183858402 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102930] New: equal values appear to be different due to missing correct rounding in libc Date: Mon, 25 Oct 2021 13:43:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net 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 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: Mon, 25 Oct 2021 13:43:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102930 Bug ID: 102930 Summary: equal values appear to be different due to missing correct rounding in libc Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Due to missing correct rounding in libc, expressions like sin(x) may give different values at compile time and at run time. With GCC optimization, th= is makes equal values appear to be different (e.g. an integer variable having = two different values at the same time). Here's a testcase, inspired by PR85957 Comment 7 (which was about the x87 extended precision). #include #include #define D1 0x1.005023d32fee5p+1 #define D2 0x0.2ef652eba3771p-1 __attribute__((noinline,noclone)) static double opaque(void) { return D1; } __attribute__((noinline,noclone)) static void t1(void) { double a =3D D1, b =3D opaque(); if (a !=3D b) printf("uneq"); double sa =3D sin(a), sb =3D sin(b); printf("t1: %a %s %a\n", sa, sa =3D=3D sb ? "=3D=3D" : "!=3D", sb); } __attribute__((noinline,noclone)) static void t2(void) { double a =3D D1, b =3D opaque(); if (a !=3D b) printf("uneq"); int ia =3D sin(a) + D2, ib =3D sin(b) + D2; printf("t2: %d %s %d\n", ia, ia =3D=3D ib ? "=3D=3D" : "!=3D", ib); } __attribute__((noinline,noclone)) static void t3(void) { double a =3D D1, b =3D opaque(); if (a !=3D b) printf("uneq"); int ia =3D sin(a) + D2, ib =3D sin(b) + D2; printf("t3: ib =3D %d\n", ib); if (ia =3D=3D ib) printf("t3: ib =3D %d\n", ib); } int main(void) { t1(); t2(); t3(); return 0; } Compile with the following options: -O2 -lm -fdisable-tree-dom3 This gives: t1: 0x1.d109ad145c88fp-1 =3D=3D 0x1.d109ad145c88ep-1 t2: 1 =3D=3D 0 t3: ib =3D 0 t3: ib =3D 1 Tested GCC versions under Debian/unstable: * gcc-8 (Debian 8.4.0-7) 8.4.0 * gcc-9 (Debian 9.4.0-3) 9.4.0 * gcc-10 (Debian 10.3.0-11) 10.3.0 * gcc-11 (Debian 11.2.0-10) 11.2.0 * gcc (Debian 20210918-1) 12.0.0 20210918 (experimental) [master r12-3644-g7afcb534239] If -fdisable-tree-dom3 is not provided, t1 still fails with GCC 8 to 11.=