From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D521F3858039; Tue, 9 Mar 2021 23:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D521F3858039 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/99497] _mm_min_ss/_mm_max_ss incorrect results when values known at compile time Date: Tue, 09 Mar 2021 23:12:34 +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: 9.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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: 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: Tue, 09 Mar 2021 23:12:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99497 --- Comment #1 from Jakub Jelinek --- Simplified: #include void print128 (__m128 var) { float val[4]; __builtin_memcpy (val, &var, sizeof(val)); __builtin_printf ("%f %f %f %f \n", val[0], val[1], val[2], val[3]); } int main () { __m128 a =3D _mm_set_ss (__builtin_nanf ("")); __m128 b =3D _mm_set_ss (2.0f); __m128 c =3D _mm_max_ss (a, b); __m128 d =3D _mm_max_ss (b, a); print128 (c); print128 (d); return 0; } The RTL SMAX etc. ops are defined as: /* Minimum and maximum values of two operands. We need both signed and unsigned forms. (We cannot use MIN for SMIN because it conflicts with a macro of the same name.) The signed variants should be used with floating point. Further, if both operands are zeros, or if either operand is NaN, then it is unspecified which of the two operands is returned as the result. */ DEF_RTL_EXPR(SMIN, "smin", "ee", RTX_COMM_ARITH) DEF_RTL_EXPR(SMAX, "smax", "ee", RTX_COMM_ARITH) DEF_RTL_EXPR(UMIN, "umin", "ee", RTX_COMM_ARITH) DEF_RTL_EXPR(UMAX, "umax", "ee", RTX_COMM_ARITH) So, if _mm*_{min,max}_ss has the same requirement on what exactly should be returned when both operands are zero or if either operand is NaN, then we probably need to use an UNSPEC unless -ffast-math tells us NaNs won't appea= r or sign of zero doesn't matter.=