From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ABFE7385E007; Fri, 16 Jul 2021 20:48:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABFE7385E007 From: "Simon.Thornington at tssecurities dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/101479] New: vectorized impossible conditional floating point operations still cause traps (-ffast-math, -O3) Date: Fri, 16 Jul 2021 20:48:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Simon.Thornington at tssecurities 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 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, 16 Jul 2021 20:48:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101479 Bug ID: 101479 Summary: vectorized impossible conditional floating point operations still cause traps (-ffast-math, -O3) Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: Simon.Thornington at tssecurities dot com Target Milestone: --- On all versions of gcc I could test, a vectorized operation of the form=20 y =3D could_be_zero ? 1.0 : (1.0 / x); in a loop will still cause an FE_DIVBYZERO, even if x_not_zero is correctly= set to true whenever x could be 0.=20=20 This is with -ffast-math and -O3. With -fno-tree-vectorize it does not occ= ur.=20 If I make could_be_zero volatile, it does not occur. If I insert a "compil= er fence" in the loop it also does not occur. At -O2 it doesn't happen either. Reproduction: #include #include #include #include #include #define FPCHECK_FORMAT(fmt, ...) \ do { \ int flags =3D fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW); \ if (flags) { \ printf("Floating point exception(s) detected:%s%s%s: %s (%s:%d) " f= mt, \ (flags & FE_INVALID) ? " FE_INVALID" : "", \ (flags & FE_DIVBYZERO) ? " FE_DIVBYZERO" : "", \ (flags & FE_OVERFLOW) ? " FE_OVERFLOW" : "", \ __func__, \ __FILE__, \ __LINE__, ## __VA_ARGS__); \ abort(); \ } \ } while(false) \ #define FPCHECK() FPCHECK_FORMAT("") #define fpcheck(where) FPCHECK_FORMAT("%s", where) #define compiler_fence() __asm__ __volatile__ ("" : : : "memory") static bool close_to_zero(double x) { return fabs(x) < 0.5; } void f(double *x, double *y, int n) { fpcheck("before"); for (int i=3D0; i