From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1D9AF38582BD; Thu, 21 Dec 2023 08:50:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D9AF38582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703148650; bh=79ka2LyXSeAeX5/7KsnXNza8lTnqjkVZQCKf2wdW/QE=; h=From:To:Subject:Date:From; b=sJqXS3lTPXVAGvfNDMqrrw4J9cu+XZ03wJ0l5Gvv1KRcfLId8QsNDH+qFhJL4b0wF Sj0+SLhTTtZbWfReKRii5aATXCJUmMlX/+w1fY/N4SCh5E+K5lt9mDTv1oWg9jh7Fb MqIFa9l4ujRJsVAPdkmJ7LjHPxsim3+cN+oDff/M= From: "xxs_chy at outlook dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113105] New: Missing optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` Date: Thu, 21 Dec 2023 08:50:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xxs_chy at outlook dot com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 Bug ID: 113105 Summary: Missing optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- Godbolt example: https://godbolt.org/z/b5va37Tzx For example: unsigned char _bin2bcd(unsigned val) { return ((val / 10) << 4) + val % 10; } can be folded to: unsigned char new_bin2bcd(unsigned val) { return val / 10 * 6 + val; } This C snippet is extracted from https://github.com/torvalds/linux/blob/master/lib/bcd.c Both GCC and LLVM missed it.=