From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B7CC13857B81; Thu, 1 Feb 2024 13:42:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7CC13857B81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706794940; bh=B4HrZfbP8A2tAMTv6ZKIa6cpCbcWK+v1UdLl1yKsgCI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZeC8DOJVVcrE/tY5v30RhYQI7dBQI8IjPV+rXF4CPIZXPRkYthfR8nKKuouWR3QSv WEsP6Kno2EPG5SCvk2Vjw/nt9pQ2KZyDQtALaAY50ildoPLjrRQOOpNl7md5z1qobj cVGetdkn+YK2HL2ZsjXjUURXUqTLq1HOQ1joBoG4= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51492] vectorizer does not support saturated arithmetic patterns Date: Thu, 01 Feb 2024 13:42:20 +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: 4.6.2 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=3D51492 --- Comment #9 from JuzheZhong --- Ok. After investigation of LLVM: Before loop vectorizer: %cond12 =3D tail call i32 @llvm.usub.sat.i32(i32 %conv5, i32 %wsize) %conv13 =3D trunc i32 %cond12 to i16 After loop vectorizer: %10 =3D call <16 x i32> @llvm.usub.sat.v16i32(<16 x i32> %9, <16 x i32> %broadcast.splat) %11 =3D trunc <16 x i32> %10 to <16 x i16> I think GCC can follow this approach, that is, first recognize scalar saturation, then fall into loop vectorizer to vectorize it into the saturation.=