From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5598D3858408; Thu, 6 Jan 2022 19:11:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5598D3858408 From: "nekotekina at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103932] New: x86: strange unoptimized code generated (multiple negations of _mm_testz_si128 result) Date: Thu, 06 Jan 2022 19:11:03 +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: nekotekina at gmail 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: Thu, 06 Jan 2022 19:11:03 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103932 Bug ID: 103932 Summary: x86: strange unoptimized code generated (multiple negations of _mm_testz_si128 result) Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nekotekina at gmail dot com Target Milestone: --- GCC generates seemingly unoptimized sequence of instructions in certain cas= es (can't tell exactly what triggers it, example code is below): xor eax, eax vptest xmm0, xmm0 sete al test eax, eax sete al movzx eax, al This should be something like this: xor eax, eax vptest xmm0, xmm0 setne al https://godbolt.org/z/sTaG65Ksc Code (-O3 -std=3Dc++20 -march=3Dskylake): #include #include #include #include template concept Vector128 =3D (sizeof(T) =3D=3D 16); using u64 =3D std::uint64_t; using u32 =3D std::uint32_t; union alignas(16) v128 { u64 _u64[2]; v128() =3D default; constexpr v128(const v128&) noexcept =3D default; template constexpr v128(const T& rhs) noexcept : v128(std::bit_cast(rhs)) { } constexpr v128& operator=3D(const v128&) noexcept =3D default; template constexpr operator T() const noexcept { return std::bit_cast(*this); } }; // Test if vector is zero inline bool gv_testz(const v128& arg) { #if defined(__SSE4_1__) return _mm_testz_si128(arg, arg); #else return !(arg._u64[0] | arg._u64[1]); #endif } struct alignas(16) context_t { v128 vec[32]; v128 sat; }; void test1(context_t& ctx, u32 n) { const u64 bit =3D !gv_testz(ctx.sat); v128 r; r._u64[0] =3D 0; r._u64[1] =3D bit; ctx.vec[n] =3D r; } void test2(context_t& ctx, u32 n) { ctx.vec[n]._u64[1] =3D !gv_testz(ctx.sat); }=