From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 920B23815FF3; Mon, 30 May 2022 08:57:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 920B23815FF3 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/53533] [10/11/12/13 regression] vectorization causes loop unrolling test slowdown as measured by Adobe's C++Benchmark Date: Mon, 30 May 2022 08:57:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 4.7.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.4 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: Mon, 30 May 2022 08:57:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53533 --- Comment #46 from rguenther at suse dot de --- On Mon, 30 May 2022, crazylht at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53533 >=20 > --- Comment #45 from Hongtao.liu --- > A reduced testcase. >=20 > int a[256]; > int b[256]; >=20 > void foo (void) > { > int i; > for (i =3D 0; i < 256; ++i) > { > int tmp =3D a[i] + 12345; > tmp *=3D 914237; > tmp +=3D 12332; > tmp *=3D 914237; > tmp +=3D 12332; > tmp *=3D 914237; > tmp -=3D 13; > tmp *=3D 8000; > b[i] =3D tmp; > } > } >=20 > GCC now simply pmulld to pslld + padd + psub, the vectorizer cost model l= ooks > fine, but for scalar version, it's extraly optimized in pass_combine fro= m 4 * > mult + 3 * add to 1 * mult + 2 * add which is not taken in count by vecto= rizer. > The vectorized version is not simplified later. >=20 > mov eax, DWORD PTR a[rdx] > add rdx, 4 > add eax, 12345 > imul eax, eax, -1564285888 > sub eax, 333519936 > mov DWORD PTR b[rdx-4], eax > cmp rdx, 1024 > jne .L2 >=20 >=20 > I'm wondering could Gimple also simplify=20 >=20 > tmp *=3D 914237; > tmp +=3D 12332; > tmp *=3D 914237; > tmp +=3D 12332; > tmp *=3D 914237; > tmp -=3D 13; > tmp *=3D 8000; >=20 > to=20 > tmp *=3D -1564285888; > tmp -=3D 333519936; >=20 > refer to https://godbolt.org/z/qYMYMTxEY >=20 > Then the vectorized code would be more optimal. The issue is that the re-association pass doesn't handle operations with undefined overflow behavior, we do have duplicate bugreports for this. On the RTL level likely simplify-rtx (or the variants used by combine) only have limited support for vector operations.=