From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 31F683858C2C; Tue, 28 Sep 2021 07:28:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31F683858C2C From: "crazylht at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102512] New: Redudant max/min operation for vector reduction Date: Tue, 28 Sep 2021 07:28:16 +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: 12.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: crazylht 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 keywords bug_severity priority component assigned_to reporter target_milestone cf_gcchost cf_gcctarget 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: Tue, 28 Sep 2021 07:28:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102512 Bug ID: 102512 Summary: Redudant max/min operation for vector reduction Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: crazylht at gmail dot com Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-*-* i?86-*-* cat test.c #define MAX(a, b) ((a) > (b) ? (a) : (b)) short foo1 (short* p) { short max =3D p[0]; for (int i =3D 0; i !=3D 8; i++) max =3D MAX(max, p[i]); return max; } short foo2 (short* p) { short max =3D p[0]; for (int i =3D 1; i !=3D 8; i++) max =3D MAX(max, p[i]); return max; } gcc -O3 -mavx2 -S=20 in foo1 the first MAX_EXPR <_10, vect__4.7_13> is redundant since it's contained by the latter .REDUC_MAX. in foo2 vectorizer failed to recognize .REDUC_MAX pattern.=20 ;; Function foo1 (foo1, funcdef_no=3D0, decl_uid=3D2991, cgraph_uid=3D1, symbol_order=3D0) .248t.optimized short int foo1 (short int * p) { vector(8) short int vect_max_11.8; vector(8) short int vect__4.7; short int max; vector(8) short int _10; short int _20; [local count: 119292720]: max_9 =3D *p_8(D); _10 =3D {max_9, max_9, max_9, max_9, max_9, max_9, max_9, max_9}; vect__4.7_13 =3D MEM [(short int *)p_8(D)]; vect_max_11.8_14 =3D MAX_EXPR <_10, vect__4.7_13>; _20 =3D .REDUC_MAX (vect_max_11.8_14); [tail call] return _20; } ;; Function foo2 (foo2, funcdef_no=3D1, decl_uid=3D3000, cgraph_uid=3D2, symbol_order=3D1) short int foo2 (short int * p) { short int stmp_max_11.21; vector(4) short int vect_max_11.20; vector(4) short int vect__4.19; short int max; short int _4; short int _25; vector(4) short int _30; short int _34; vector(4) short int _38; vector(4) short int _39; vector(4) short int _40; vector(4) short int _41; short int _44; short int _46; [local count: 268435454]: max_9 =3D *p_8(D); _30 =3D {max_9, max_9, max_9, max_9}; vect__4.19_35 =3D MEM [(short int *)p_8(D) + 2B]; vect_max_11.20_36 =3D MAX_EXPR <_30, vect__4.19_35>; _38 =3D VEC_PERM_EXPR ; _39 =3D MAX_EXPR ; _40 =3D VEC_PERM_EXPR <_39, { 0, 0, 0, 0 }, { 1, 2, 3, 4 }>; _41 =3D MAX_EXPR <_39, _40>; stmp_max_11.21_42 =3D BIT_FIELD_REF <_41, 16, 0>; _4 =3D MEM[(short int *)p_8(D) + 10B]; _46 =3D MEM[(short int *)p_8(D) + 12B]; _34 =3D MAX_EXPR <_4, _46>; _25 =3D MEM[(short int *)p_8(D) + 14B]; _44 =3D MAX_EXPR <_25, stmp_max_11.21_42>; max_26 =3D MAX_EXPR <_34, _44>; return max_26; }=