From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B8D493858C83; Fri, 22 Apr 2022 21:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8D493858C83 From: "john_platts at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105353] New: __builtin_shufflevector with template parameter fails to compile on GCC 12 but compiles on clang Date: Fri, 22 Apr 2022 21:07:58 +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: john_platts at hotmail 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, 22 Apr 2022 21:07:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105353 Bug ID: 105353 Summary: __builtin_shufflevector with template parameter fails to compile on GCC 12 but compiles on clang Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: john_platts at hotmail dot com Target Milestone: --- The following code fails to compile with GCC 12 but compiles successfully on clang (with the -std=3Dc++17 flag): #include typedef std::uint8_t Simd128U8VectT __attribute__((__vector_size__(16))); template static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept { if constexpr(unsigned(ShuffleIndex) >=3D 16) return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0= , 0 }; else if constexpr(ShuffleIndex =3D=3D 0) return vect; else return __builtin_shufflevector(vect, vect, ShuffleIndex, ShuffleInd= ex + 1, ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIn= dex + 5, ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIn= dex + 9, ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13, ShuffleIndex + 14, ShuffleIndex + 15); } auto func1(Simd128U8VectT vect) noexcept { return ShufFunc<5>(vect); } Here is the assembly output when the above code is compiled on clang 14.0.0 with the -O2 -std=3Dc++17 flags: func1(unsigned char __vector(16)): # @func1(unsigned char __vector(16)) movdqa xmm1, xmm0 psrldq xmm1, 5 # xmm1 =3D xmm1[5,6,7,8,9,10,11,12,13,14,15],zero,zero,zero,zero,zero pslldq xmm0, 11 # xmm0 =3D zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,xmm0[0,1,2,3,4] por xmm0, xmm1 ret The below code compiles successfully with GCC 11 and GCC 12 (which uses __builtin_shuffle instead of __builtin_shufflevector): #include typedef std::uint8_t Simd128U8VectT __attribute__((__vector_size__(16))); template static inline Simd128U8VectT ShufFunc(Simd128U8VectT vect) noexcept { if constexpr(unsigned(ShuffleIndex) >=3D 16) return Simd128U8VectT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0= , 0 }; else if constexpr(ShuffleIndex =3D=3D 0) return vect; else return __builtin_shuffle(vect, vect, (Simd128U8VectT){ ShuffleIndex, ShuffleIndex + 1, ShuffleIndex + 2, ShuffleIndex + 3, ShuffleIndex + 4, ShuffleIn= dex + 5, ShuffleIndex + 6, ShuffleIndex + 7, ShuffleIndex + 8, ShuffleIn= dex + 9, ShuffleIndex + 10, ShuffleIndex + 11, ShuffleIndex + 12, ShuffleIndex + 13, ShuffleIndex + 14, ShuffleIndex + 15 }); } auto func1(Simd128U8VectT vect) noexcept { return ShufFunc<5>(vect); }=