From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C646038207EB; Thu, 23 Jun 2022 01:59:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C646038207EB From: "goldstein.w.n at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106060] New: Inefficient constant broadcast on x86_64 Date: Thu, 23 Jun 2022 01:59:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: goldstein.w.n 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, 23 Jun 2022 01:59:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106060 Bug ID: 106060 Summary: Inefficient constant broadcast on x86_64 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: goldstein.w.n at gmail dot com Target Milestone: --- ``` #include __m256i shouldnt_have_movabs () { return _mm256_set1_epi8 (123); } __m256i should_be_cmpeq_abs () { return _mm256_set1_epi8 (1); } __m256i should_be_cmpeq_add () { return _mm256_set1_epi8 (-2); } ``` Compiled with: '-O3 -march=3Dx86-64-v3' Results in: ``` Disassembly of section .text: 0000000000000000 : 0: 48 b8 7b 7b 7b 7b 7b movabs $0x7b7b7b7b7b7b7b7b,%rax 7: 7b 7b 7b a: c4 e1 f9 6e c8 vmovq %rax,%xmm1 f: c4 e2 7d 59 c1 vpbroadcastq %xmm1,%ymm0 14: c3 retq 15: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 1c: 00 00 00 00 0000000000000020 : 20: 48 b8 01 01 01 01 01 movabs $0x101010101010101,%rax 27: 01 01 01 2a: c4 e1 f9 6e c8 vmovq %rax,%xmm1 2f: c4 e2 7d 59 c1 vpbroadcastq %xmm1,%ymm0 34: c3 retq 35: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 3c: 00 00 00 00 0000000000000040 : 40: 48 b8 fe fe fe fe fe movabs $0xfefefefefefefefe,%rax 47: fe fe fe 4a: c4 e1 f9 6e c8 vmovq %rax,%xmm1 4f: c4 e2 7d 59 c1 vpbroadcastq %xmm1,%ymm0 54: c3 retq ``` Compiled with: '-O3 -march=3Dx86-64-v4' Results in: ``` 0000000000000000 : 0: 48 b8 7b 7b 7b 7b 7b movabs $0x7b7b7b7b7b7b7b7b,%rax 7: 7b 7b 7b a: 62 f2 fd 28 7c c0 vpbroadcastq %rax,%ymm0 10: c3 retq 11: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 18: 00 00 00 00 1c: 0f 1f 40 00 nopl 0x0(%rax) 0000000000000020 : 20: 48 b8 01 01 01 01 01 movabs $0x101010101010101,%rax 27: 01 01 01 2a: 62 f2 fd 28 7c c0 vpbroadcastq %rax,%ymm0 30: c3 retq 31: 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1) 38: 00 00 00 00 3c: 0f 1f 40 00 nopl 0x0(%rax) 0000000000000040 : 40: 48 b8 fe fe fe fe fe movabs $0xfefefefefefefefe,%rax 47: fe fe fe 4a: 62 f2 fd 28 7c c0 vpbroadcastq %rax,%ymm0 50: c3 retq ``` All functions / targets are inoptimal. Generating 1/2 can be done without any lane-cross broadcast. Generating constants like 123 shouldn't first be constant broadcast into an imm64. That makes it require an 10-byte `movabs` and wastes spaces.=