From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 69A363858434; Tue, 6 Feb 2024 22:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69A363858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707257470; bh=ljW6gPBE1rEhhnePuKw3yaoMq+dXSVkhdc8rgoVDH8o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=izHw7Y4rlOm1b0nL2tg9Xloiwuea3W1n96vXzIaoFI2a430Dj1DIxPcdTc2/AshX6 y/+4glgw4db7I9mRo4ElC7P1dlZ1/3hm2teO2f7/A3e/WXckJW5pqwFzVjWGaBx9ic 3689Wn/yAb1C0Fn7rOtoK4mJri/Sc/4fuH+oKHjk= From: "tnfchris at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51492] vectorizer does not support saturated arithmetic patterns Date: Tue, 06 Feb 2024 22:11:08 +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: tnfchris at gcc dot gnu.org 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 #17 from Tamar Christina --- (In reply to Li Pan from comment #16) > I have a try like below and finally have the Standard Name "SAT_ADD". Cou= ld > you please help to double-check if my understanding is correct? >=20 > Given below example code below: >=20 > typedef unsigned int uint32_t; >=20 > uint32_t > sat_add (uint32_t x, uint32_t y) > { > return (x + y) | - ((x + y) < x); > } >=20 > And then add one simpify to match.pd and define new DEF_INTERNAL_OPTAB_FN > for it. Then we have the SAT_ADD representation after expand. >=20 > uint32_t sat_add (uint32_t x, uint32_t y) > { > uint32_t _6; >=20 > ;; basic block 2, loop depth 0 > ;; pred: ENTRY > _6 =3D .SAT_ADD (x_4(D), y_5(D)); [tail call] > return _6; > ;; succ: EXIT >=20 > } >=20 > If everything goes well, I will prepare the patch for it later. Thanks. Yeah that's looks right, I assume above you mean before expand? I believe saturating add is commutative but not associative, so you'd want = to add it to commutative_binary_fn_p in internal-fn.cc. You may also want to provide some basic optimizations for it in match.pd su= ch as .SAT_ADD (a, 0) =3D a. etc.=