From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 69CF2385B51A; Wed, 8 Mar 2023 15:07:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69CF2385B51A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678288048; bh=27uwHwt1FUL6qa4owOzW5R+Zjv5rjDnVPyVd/OgdbSw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uPnbgFnIHjkCJauucPhYAwro5AvpDhu/6XtheI+PugXFi/WSEgr06FAwNN72pn4l0 j/0Xj0nNe7a9blaOpNHeKQyO58dJVF+YB3hL6LIAtFcIkX6/yyUGJQwEKVMK/CpcvS 772U570bpd8MkBijykt+iPkfrEzbIwZ+8L+jzmhg= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109008] [13 Regression] Wrong code in scipy package since r13-3926-gd4c2f1d376da6f Date: Wed, 08 Mar 2023 15:07:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109008 --- Comment #34 from Jakub Jelinek --- Testing I've performed so far (though on 10000 iterations rather than 30000= 0, that is ongoing), once with the https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109008#c33 patch alone, once= with that patch and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109008#c32. First step, generate a random testcase: pr109008-gen.c: #include #include #include #include static long rand_n; static int rand_c; static uint32_t get_rand32 (void) { uint32_t ret =3D 0; if (rand_c =3D=3D 0) { ret =3D random () & 0x7fffffff; rand_c =3D 31; } else ret =3D rand_n & (((uint32_t) 1 << rand_c) - 1); ret <<=3D (32 - rand_c); rand_n =3D random (); ret |=3D rand_n & (((uint32_t) 1 << (32 - rand_c)) - 1); rand_n >>=3D (32 - rand_c); rand_c =3D 31 - (32 - rand_c); return ret; } static uint64_t get_rand64 (void) { return (((uint64_t) get_rand32 ()) << 32) | get_rand32 (); } static float get_randf (void) { uint32_t i =3D get_rand32 (); float f; memcpy (&f, &i, sizeof (f)); return f; } int main () { printf ("#define nanf __builtin_nanf (\"\")\n"); printf ("#define inf __builtin_inff ()\n"); for (int n =3D 0; n < 300000; ++n) { float n1 =3D get_randf (); float n2 =3D get_randf (); uint32_t x =3D get_rand32 (); if ((x & 7) =3D=3D 0) n2 =3D n1; x >>=3D 3; printf ("float f%d (float eps) { float f =3D ", n); switch (x % 3) { case 0: printf ("%af + eps", n1); break; case 1: printf ("%af - eps", n1); break; case 2: printf ("eps - %af", n1); break; } printf ("; if (f =3D=3D %af) return eps; return __builtin_nanf (\"42\= "); }\n", n2); } return 0; } pr109008-main.c: #include #include "pr109008.c" struct S { float (*fn) (float); float lb, ub; }; struct S arr[] =3D { #include "pr109008.h" }; int main () { float plus_inf =3D __builtin_inf (); float minus_inf =3D -plus_inf; for (int i =3D 0; i < sizeof (arr) / sizeof (arr[0]); ++i) { float lb =3D nextafterf (arr[i].lb, minus_inf); float ub =3D nextafterf (arr[i].ub, plus_inf); if (!__builtin_isnan (arr[i].fn (lb)) || !__builtin_isnan (arr[i].fn (ub))) __builtin_printf ("%p err\n", arr[i].fn); } } gcc -g -O2 -o pr109008-gen{,.c}; ./pr109008-gen > pr109008.c Next, with cc1 built with just #c33 patch: rm -f /tmp/ranges; ./cc1 -quiet -O2 pr109008.c; sort -u /tmp/ranges > pr109008.h gcc -g -o pr109008-main{,.c}; ./pr109008-main For 10000 iterations this showed 872 errors. Next, with cc1 built with both #c32 and #c33 patches: rm -f /tmp/ranges; ./cc1 -quiet -O2 pr109008.c; sort -u /tmp/ranges > pr109008.h gcc -g -o pr109008-main{,.c}; ./pr109008-main This didn't print any errors, so at least for foperator_plus and foperator_minus seems to be from this limited testing conservatively correct. Want to finish now this testing also for 300000 iterations and then perhaps= try the #c30 patch with variant of #c33 to check also that implementation. And finally compare the #c32+#c33 vs. #c30+#c33variant ranges. Another thing which would be nice to think about is whether float_widen_lhs_range needs to extend even real_{min,max}_representable () bounds towards -+inf, = or whether that case can't happen (and check that separately for + or - and * or /), because e.g. for mult/div whether lhs is finite is quite important.=