From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D28D93858C60; Wed, 7 Feb 2024 08:08:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D28D93858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707293308; bh=x+zAUIIP04oUa3njWnKN4TcSuMJ4GpGwrB5n06ljaZg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PqlrmZXmnbCp+oSRh+hAxRp8a6ki4Itwmw4Q9HqqYf4g5oczJ/8Vo+TAq0JgHEZsy n4mOlJKwbHbbald9lp9jXVCuNbq9xgomHYo0ipIurSy5hbRL9kAXDTaY6+C/r+vuEd va38cwX0c32P1L65Xj8WkM+VsD17m1d9P0oqDimQ= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113583] Main loop in 519.lbm not vectorized. Date: Wed, 07 Feb 2024 08:08:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: juzhe.zhong at rivai dot ai 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113583 --- Comment #15 from JuzheZhong --- (In reply to rguenther@suse.de from comment #14) > On Wed, 7 Feb 2024, juzhe.zhong at rivai dot ai wrote: >=20 > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113583 > >=20 > > --- Comment #13 from JuzheZhong --- > > Ok. I found the optimized tree: > >=20 > >=20 > > _5 =3D 3.33333333333333314829616256247390992939472198486328125e-1 - _= 4; > > _8 =3D .FMA (_5, 1.22999999999999998223643160599749535322189331054687= 5e-1, _4); > >=20 > > Let CST0 =3D 3.33333333333333314829616256247390992939472198486328125e-1, > > CST1 =3D 1.229999999999999982236431605997495353221893310546875e-1 > >=20 > > The expression is equivalent to the following: > >=20 > > _5 =3D CST0 - _4; > > _8 =3D _5 * CST1 + 4; > >=20 > > That is: > >=20 > > _8 =3D (CST0 - _4) * CST1 + 4; > >=20 > > So, We should be able to re-associate it like Clang: > >=20 > > _8 =3D CST0 * CST1 - _4 * CST1 + 4; ---> _8 =3D CST0 * CST1 + _4 * (1 -= CST1); > >=20 > > Since both CST0 * CST1 and 1 - CST1 can be pre-computed during compilat= ion > > time. > >=20 > > Let say CST2 =3D CST0 * CST1, CST3 =3D 1 - CST1, then we can re-associa= te as Clang: > >=20 > > _8 =3D FMA (_4, CST3, CST2). > >=20 > > Any suggestions for this re-association ? Is match.pd the right place = to do it > > ? >=20 > You need to look at the IL before we do .FMA forming, specifically=20 > before/after the late reassoc pass. There pass applying match.pd > patterns everywhere is forwprop. >=20 > I also wonder which compilation flags you are using (note clang > has different defaults for example for -ftrapping-math) Both GCC and Clang are using -Ofast -ffast-math.=