From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3EFC3858C74; Wed, 27 Sep 2023 02:58:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3EFC3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695783531; bh=Fh/ByXNbFs8Br+i4obuFUAVo454B1mb3hlcohC/dHU4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AEHHsOp+rjHM+lGYeSvxihNyv7uNdPWVteCXf/5zdOmrLYeksWmJb2jxDKseURoKB 138rwGE/nRzbRlTc7a+0t0pSfPr9nBlXRNFC3EDPv6nfqt6CMLuxu4k0Z49wJ4//ao iSk5Kw7SC1vJD2Q0SJgNdsKTSC55DUV6HYyQBKMA= 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: Wed, 27 Sep 2023 02:58:51 +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 #8 from JuzheZhong --- It's because the order of the operations we are doing: For code as follows: result +=3D mask ? a[i] + x : 0; GCC: result_ssa_1 =3D PHI ... STMT 1. tmp =3D a[i] + x; STMT 2. tmp2 =3D tmp + result_ssa_1; STMT 3. result_ssa_2 =3D mask ? tmp2 : result_ssa_1; Here we can see both STMT 2 and STMT 3 are using 'result_ssa_1', we end up with 2 uses of the PHI result. Then, we failed to vectorize. Wheras LLVM: result_ssa_1 =3D PHI ... IR 1. tmp =3D a[i] + x; IR 2. tmp2 =3D mask ? tmp : 0; IR 3. result_ssa_2 =3D tmp2 + result_ssa_1. LLVM only has 1 use. Is it reasonable to swap the order in match.pd ?=