From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A90123858C2A; Thu, 21 Dec 2023 16:09:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A90123858C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703174999; bh=pBO/+BbQLBxwkkog0o/P3tt3LPPmXuXyJGtJX4WiibY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wRa3nPCNmZkRYGrX5JdpbMeVZYe1Xr0vAh62LhMnBC16COKx5aduVMHfDNLBJSXp5 3yvqSAp/ecDymuqCZRj3f1kyx2iS4TcKAuy+WmWeurjksOUZwAZgWV5yEtCWrYm7Bi R55xtZ6lZZc+HltIYRo3laMUjc6ak3NR38QesLII= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113105] Missing optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` Date: Thu, 21 Dec 2023 16:09:59 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jakub at gcc dot gnu.org 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: 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=3D113105 --- Comment #1 from Jakub Jelinek --- When it is signed v / a * b + v % a, I think it can introduce UB which wasn= 't there originally. E.g. for v =3D 0, a =3D INT_MIN and b =3D 3. So, if it isn't done just for= unsigned types, parts of it need to be done in unsigned.=