From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E5E2C395340E; Thu, 7 Jan 2021 12:52:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5E2C395340E From: "ktkachov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98581] New: unexpected reassociation for umin/umax ? Date: Thu, 07 Jan 2021 12:52:05 +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: unknown X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: ktkachov at gcc dot gnu.org 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 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, 07 Jan 2021 12:52:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98581 Bug ID: 98581 Summary: unexpected reassociation for umin/umax ? Product: gcc Version: unknown Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- typedef signed int *__restrict__ pSINT; typedef unsigned int *__restrict__ pUINT; #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) void saba_s (pSINT a, pSINT b, pSINT c) { int i; for (i =3D 0; i < 4; i++) c[i] +=3D (MAX (a[i], b[i]) - MIN (a[i], b[i])); } void saba_u (pUINT a, pUINT b, pUINT c) { int i; for (i =3D 0; i < 4; i++) c[i] +=3D (MAX (a[i], b[i]) - MIN (a[i], b[i])); } On aarch64 at -O3 generates: saba_s: ldr q0, [x0] ldr q1, [x1] ldr q2, [x2] sabd v0.4s, v0.4s, v1.4s add v0.4s, v0.4s, v2.4s str q0, [x2] ret saba_u: ldr q1, [x0] ldr q2, [x1] ldr q3, [x2] umax v0.4s, v1.4s, v2.4s umin v1.4s, v1.4s, v2.4s add v0.4s, v0.4s, v3.4s sub v0.4s, v0.4s, v1.4s str q0, [x2] ret I would expect the (MAX (a[i], b[i]) - MIN (a[i], b[i])) part to match a ua= bd instruction for the unsigned case, but it looks like the add and sub operat= ions are swapped which prevents the RTL pattern matching the operation. This comes out this way out of GIMPLE. At expand the signed version is: vect__4.6_40 =3D MEM [(int *)c_16(D)]; vect__6.9_37 =3D MEM [(int *)b_17(D)]; vect__8.12_34 =3D MEM [(int *)a_18(D)]; vect__9.13_33 =3D MAX_EXPR ; vect__10.14_32 =3D MIN_EXPR ; vect__11.15_31 =3D vect__9.13_33 - vect__10.14_32; vect__12.16_30 =3D vect__11.15_31 + vect__4.6_40; MEM [(int *)c_16(D)] =3D vect__12.16_30; return; the unsigned is: vect__4.25_38 =3D MEM [(unsigned int *)c_16(D)]; vect__6.28_35 =3D MEM [(unsigned int *)b_17(D)]; vect__8.31_32 =3D MEM [(unsigned int *)a_18(D)]; vect__9.32_31 =3D MAX_EXPR ; vect__10.33_30 =3D MIN_EXPR ; vect__13.34_29 =3D vect__9.32_31 + vect__4.25_38; vect__12.35_28 =3D vect__13.34_29 - vect__10.33_30; MEM [(unsigned int *)c_16(D)] =3D vect__12.35_28; return;=