From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C46C7385BF9C; Fri, 26 Feb 2021 10:18:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C46C7385BF9C From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/99234] [10/11 regression] wrong result for 1.0/3.0 with -O2 -fno-omit-frame-pointer -frounding-math Date: Fri, 26 Feb 2021 10:18:39 +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: 10.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ebotcazou at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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: Fri, 26 Feb 2021 10:18:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99234 --- Comment #17 from Jakub Jelinek --- (In reply to Liu Hao from comment #15) > Thanks. The 'Final fix' looks good to me. >=20 > I applied it locally and built GCC. With a debugger, I verified that after > the try-catch statement, all non-volatile XMM registers (6-15) had been > restored properly. >=20 >=20 >=20 > ``` > // x86_64-w64-mingw32-g++ -O2 -fno-omit-frame-pointer test.cc >=20 > __attribute__((__noinline__)) void clobber_xmm6() > { > __asm__ volatile ("xorpd %%xmm6, %%xmm6" ::: "xmm6"); > throw 42; // remove this to get expected result > } >=20 > int main() > { > static const double xmm5 =3D 5.123456; > static const double xmm6 =3D 6.123456; > static const double xmm7 =3D 7.123456; > static const double xmm8 =3D 8.123456; > static const double xmm9 =3D 9.123456; > static const double xmm10 =3D 10.123456; > static const double xmm11 =3D 11.123456; > static const double xmm12 =3D 12.123456; > static const double xmm13 =3D 13.123456; > static const double xmm14 =3D 14.123456; > static const double xmm15 =3D 15.123456; > __asm__ volatile ("movsd %0, %%xmm5 " :: "m"(xmm5 )); That would certainly need : "xmm5" in clobbers (etc.). And isn't really portable anyway, the compiler can choose to put anything into %xmm6 in between that and the asm before printf. But, loading the value from memory into some double temporary (with "=3Dx" = for many of them) in an asm and then e.g. just "+x" them in empty asms and then comparing val= ues will likely reproduce it too. > __asm__ volatile ("movsd %0, %%xmm6 " :: "m"(xmm6 )); > __asm__ volatile ("movsd %0, %%xmm7 " :: "m"(xmm7 )); > __asm__ volatile ("movsd %0, %%xmm8 " :: "m"(xmm8 )); > __asm__ volatile ("movsd %0, %%xmm9 " :: "m"(xmm9 )); > __asm__ volatile ("movsd %0, %%xmm10" :: "m"(xmm10)); > __asm__ volatile ("movsd %0, %%xmm11" :: "m"(xmm11)); > __asm__ volatile ("movsd %0, %%xmm12" :: "m"(xmm12)); > __asm__ volatile ("movsd %0, %%xmm13" :: "m"(xmm13)); > __asm__ volatile ("movsd %0, %%xmm14" :: "m"(xmm14)); > __asm__ volatile ("movsd %0, %%xmm15" :: "m"(xmm15)); >=20 > try { > clobber_xmm6(); > } > catch(...) { } >=20 > double value; > __asm__ volatile ("movsd %%xmm6, %0" : "=3Dx"(value)); > __builtin_printf("value =3D %g\n", value); // expect `123.456` You mean 6.123456 ? And in any case, I'd suggest whatever.625 or other constants which won't suffer from rounding etc.=