From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8F41D3858438; Mon, 18 Jul 2022 18:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F41D3858438 From: "manolis.tsamis at vrull dot eu" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106346] New: Potential regression on vectorization of left shift with constants Date: Mon, 18 Jul 2022 18:28:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: manolis.tsamis at vrull dot eu 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 keywords bug_severity priority component assigned_to reporter target_milestone cf_gcctarget attachments.created 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: Mon, 18 Jul 2022 18:28:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106346 Bug ID: 106346 Summary: Potential regression on vectorization of left shift with constants Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: manolis.tsamis at vrull dot eu Target Milestone: --- Target: aarch64 Created attachment 53317 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53317&action=3Dedit Does not vectorize on GCC > 10.3 The following test case: void foo (uint32_t dst[8], uint8_t src1[8], uint8_t src2[8]) { uint16_t diff_e0 =3D src1[0] - src2[0]; uint16_t diff_e1 =3D src1[1] - src2[1]; uint16_t diff_e2 =3D src1[2] - src2[2]; uint16_t diff_e3 =3D src1[3] - src2[3]; uint16_t diff_e4 =3D src1[4] - src2[4]; uint16_t diff_e5 =3D src1[5] - src2[5]; uint16_t diff_e6 =3D src1[6] - src2[6]; uint16_t diff_e7 =3D src1[7] - src2[7]; uint32_t a0 =3D diff_e0 << 1; uint32_t a1 =3D diff_e1 << 3; uint32_t a2 =3D diff_e2 << 4; uint32_t a3 =3D diff_e3 << 2; uint32_t a4 =3D diff_e4 << 12; uint32_t a5 =3D diff_e5 << 11; uint32_t a6 =3D diff_e6 << 9; uint32_t a7 =3D diff_e7 << 3; dst[0] =3D a0; dst[1] =3D a1; dst[2] =3D a2; dst[3] =3D a3; dst[4] =3D a4; dst[5] =3D a5; dst[6] =3D a6; dst[7] =3D a7; } Compiles at -O3 to nice vectorized code by loading the constants from memor= y in GCC 10.3: ldr d0, [x1] adrp x3, .LC0 ldr d1, [x2] adrp x1, .LC1 ldr q3, [x3, #:lo12:.LC0] usubl v0.8h, v0.8b, v1.8b ldr q2, [x1, #:lo12:.LC1] uxtl v1.4s, v0.4h uxtl2 v0.4s, v0.8h sshl v1.4s, v1.4s, v3.4s sshl v0.4s, v0.4s, v2.4s stp q1, q0, [x0] ret But this has regressed in later releases, with GCC still loading the consta= nts from memory but also emitting a lot of scalar code before that. For example= GCC 13 produces: adrp x3, .LC0 ldrb w6, [x1, 4] fmov d0, x6 ldrb w7, [x1] ldr q5, [x3, #:lo12:.LC0] fmov d1, x7 ldrb w3, [x1, 5] ldrb w4, [x1, 1] ldrb w8, [x2, 4] ldrb w5, [x2, 5] ins v0.h[1], w3 ldrb w6, [x2] fmov d2, x8 ldrb w3, [x2, 1] fmov d3, x6 ins v2.h[1], w5 ins v1.h[1], w4 ldrb w9, [x1, 2] ins v3.h[1], w3 ldrb w8, [x1, 6] ldrb w7, [x2, 2] ldrb w6, [x2, 6] ins v1.h[2], w9 ins v0.h[2], w8 ldrb w5, [x1, 3] ins v3.h[2], w7 ldrb w4, [x1, 7] ins v2.h[2], w6 ldrb w1, [x2, 7] ldrb w3, [x2, 3] ins v1.h[3], w5 ins v0.h[3], w4 ins v2.h[3], w1 ins v3.h[3], w3 adrp x1, .LC1 ldr q4, [x1, #:lo12:.LC1] sub v1.4h, v1.4h, v3.4h sub v0.4h, v0.4h, v2.4h uxtl v1.4s, v1.4h uxtl v0.4s, v0.4h sshl v1.4s, v1.4s, v5.4s sshl v0.4s, v0.4s, v4.4s stp q1, q0, [x0] ret Interestingly, this happens only with left shift and not with right shift. GCC 10.3 vs trunk comparison: https://godbolt.org/z/xWbfGdfen=