From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4F0153858D35; Mon, 27 Feb 2023 12:36:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F0153858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677501361; bh=JdOMb2MahmBStjsvl6z0LeMQnbJnql4S2I2GIjOFpBU=; h=From:To:Subject:Date:From; b=D8Cka3350D90xpST4nNpV9D9YNxuxzvK+VBUPIwWcA7qy6emW5pckIh05sEYRLX0C 4/o1o6dge2IVn9kmmVcC4ag1nIhjWuYR+dLJT/FoqJEdNunErLRHeqTqfk9o4a3EMY SgCBM9vJm7rl6TfNjil96iz38qomVbPSyqpwT9qc= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108949] New: Optimize shift counts Date: Mon, 27 Feb 2023 12:36:00 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal 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: 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=3D108949 Bug ID: 108949 Summary: Optimize shift counts Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- >From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108941#c13 : Because various backends support shift count truncation or have patterns th= at recognize it in certain cases, I wonder if middle-end couldn't canonicalize shift count (N + x) where N is multiple of shift first operand's bitsize B to x & (B - 1) where= the latter is often optimized away while the former is not. For similar N - x it is more questionable because N - x is a single GIMPLE statement while -y & (B - 1) are two; perhaps it could be done at expansion time though. In generic code at least for SHIFT_COUNT_TRUNCATED targets, otherwise maybe= if one can easily detect negation optab and subtraction instruction not accept= ing immediate for the minuend. Or handle all this in each of the backends? int foo (int x, int y) { return x << (y & 31); } int bar (int x, int y) { return x << (32 + y); } int baz (int x, int y) { return x << (-y & 31); } int qux (int x, int y) { return x << (32 - y); }=