From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A47E83851C29; Tue, 23 Mar 2021 14:08:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A47E83851C29 From: "kretz at kde dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99728] code pessimization when using wrapper classes around SIMD types Date: Tue, 23 Mar 2021 14:08:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: kretz at kde dot 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, 23 Mar 2021 14:08:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99728 --- Comment #4 from Matthias Kretz (Vir) --- FWIW, using std::experimental::native_simd also does not hoist the stores out of the loop. However, if you pass d by value and return d, the i= ssue goes away. So I guess this is an aliasing pessimization. Even though you ad= ded __restrict__. In any case __m256 has the problem that it is declared with t= he may_alias attribute. I recommend to just never use __m256 unless you have no other choice. Note that `s0data_s<__m256d>` warns "ignoring attributes on template argument '__m256d' [-Wignored-attributes]", meaning it drops the may_alias attribute. Reduced test case (https://godbolt.org/z/PW98Wsfoj): #include struct Tvsimple { __m256d v; }; struct s0data_s { Tvsimple lam1, lam2; }; struct s0data_s_intrin { __m256d lam1, lam2; }; template void foo(T &__restrict__ d, size_t l, size_t lmax) { while (l <=3D lmax) { d.lam1 =3D d.lam2; l +=3D 2; } } // hoists load out of the loop but loops over the store template void foo<>(s0data_s &__restrict__ d, size_t l, size_t lmax); // turns loop into a single branch template void foo<>(s0data_s_intrin &__restrict__ d, size_t l, size_t lmax)= ;=