From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6B8BC385842C; Tue, 26 Sep 2023 12:14:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B8BC385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695730451; bh=AfDzzryPmWPFF6Ntj5Ecft5pDtq+36mUfFsqA9cr3lc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uGk25DPrEOe15xekn/2tbhyZQ8fsJH/pO0wYlnCMxPZu6ZFJGWpsdPRc+lLaUnHJS 36WJk1QiKlrXQV1FtggERwhFJvtYi0vqxTutOBdNQ5uJyTIbR7vKToGxmVzVaWREQP B3JOU+NwLVNp58yAMyjyGc2XmsixMXelrxyeG78A= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109088] GCC does not always vectorize conditional reduction Date: Tue, 26 Sep 2023 12:14:10 +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: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: juzhe.zhong at rivai dot ai X-Bugzilla-Status: NEW 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=3D109088 --- Comment #6 from JuzheZhong --- After investigations: GCC failed to vectorize reduction with multiple conditional operations: ifcvt dump: # result_20 =3D PHI ... _11 =3D result_20 + 10; result_17 =3D _4 + _11; _23 =3D _4 > _7; result_9 =3D _23 ? result_17 : result_20; It's odd that GCC failed to vectorize it since they are not complicate statements. In LLVM, it will vectorize them into: vector_ssa_2 =3D ... vector_ssa_1 =3D vector_ssa_2 + 10; vector_ssa_3 =3D vector_ssa_1 + 10; mask_ssa_1 =3D vector_ssa_4 > vector_ssa_5; vector_ssa_result =3D select I think GCC should be able to vectorize it like LLVM: vector_ssa_2 =3D ... vector_ssa_1 =3D vector_ssa_2 + 10; vector_ssa_3 =3D vector_ssa_1 + 10; mask_ssa_1 =3D vector_ssa_4 > vector_ssa_5; vector_ssa_result =3D VCOND_MASK I saw this code disable the vectorization: else if (!bbs.is_empty () && bb->loop_father->header =3D=3D bb && bb->loop_father->dont_vectorize) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "splitting region at dont-vectorize loop %d " "entry at bb%d\n", bb->loop_father->num, bb->index); split =3D true; } I am not familiar with these codes, any ideas ? Thanks.=