From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 93BFD3858425; Thu, 9 Nov 2023 12:27:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93BFD3858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699532870; bh=nzrf305ZcBvcRIWj+ows7p3FSUwV4IpsO094OsmG4qU=; h=From:To:Subject:Date:From; b=JuNkZlqebD/5EPqJ6Cu45jksg47c16v1BuH1PYXAeIFJTFsqeFEgLbxmu81dOLo/L aLRVoU8CZDHs3Qh0ouUj80eLBEDHB1W3gFocz7Z1X3YFwY3lAzT/oudbOlO1b42GqW pDIl4IPmPGhIIcDXtZ+r2RziQVSPpz2YmiDCQ1jw= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112457] New: Possible better vectorization of different reduction min/max reduction Date: Thu, 09 Nov 2023 12:27:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal 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: bug_id short_desc product version bug_status 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112457 Bug ID: 112457 Summary: Possible better vectorization of different reduction min/max reduction Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: juzhe.zhong at rivai dot ai Target Milestone: --- Hi, Richard. GCC-14 almost has all features of RVV. I am planning to participate on improving GCC loop vectorizer in GCC-15. Fix FAILs of TSVC is one of my plan. Currently we can vectorize this following case: int idx =3D 0; int max =3D 0; void foo (int n, int * __restrict a){ for (int i =3D 0; i < n; ++i) { max =3D max < a[i] ? a[i] : max; } } However, if we change this case it failed: void foo2 (int n, int * __restrict a){ for (int i =3D 0; i < n; ++i) { if (max < a[i]) { max =3D a[i]; } else max =3D max; } } Now, I notice another interesting and possible vectorization enhancement wh= ich inspired by this patch of LLVM: https://reviews.llvm.org/D143465 And more advance case is which is case from LLVM patch: which is vectorization reduction with index: void foo3 (int n, int * __restrict a){ for (int i =3D 0; i < n; ++i) { if (max < a[i]) { idx =3D i; max =3D a[i]; } } } I wonder it is a valuable optimization ? If yes, it would be one of my TODO list. Thanks.=