From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 7ED333858D1E for ; Mon, 11 Jul 2022 18:10:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7ED333858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 26BI96Zk010628; Mon, 11 Jul 2022 13:09:06 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 26BI96fJ010627; Mon, 11 Jul 2022 13:09:06 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 11 Jul 2022 13:09:05 -0500 From: Segher Boessenkool To: HAO CHEN GUI Cc: gcc-patches , David , "Kewen.Lin" , Peter Bergner Subject: Re: [PATCH v2] Modify combine pattern by a pseudo AND with its nonzero bits [PR93453] Message-ID: <20220711180905.GH25951@gate.crashing.org> References: <368de06c-f6d6-e759-0f91-5df170687346@linux.ibm.com> <20220707173140.GY25951@gate.crashing.org> <8405f869-def3-3470-257a-46dac8b99bb9@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8405f869-def3-3470-257a-46dac8b99bb9@linux.ibm.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2022 18:10:08 -0000 Hi! On Mon, Jul 11, 2022 at 10:13:41AM +0800, HAO CHEN GUI wrote: > I did a biset for the problem. After commit "commit 8d2d39587: combine: Do not combine > moves from hard registers", the case fails. The root cause is it can't combine from the > hard registers and has to use subreg which causes its high part to be undefined. Thus, > there is an additional "AND" generated. > > Before the commit > Trying 2 -> 7: > 2: r125:DI=%3:DI > REG_DEAD %3:DI > 7: r128:SI=r125:DI#0 0>>0x1f > REG_DEAD r125:DI > Successfully matched this instruction: > (set (reg:SI 128 [ x ]) > (lshiftrt:SI (reg:SI 3 3 [ x ]) > (const_int 31 [0x1f]))) > allowing combination of insns 2 and 7 > > After the commit > Trying 20 -> 7: > 20: r125:DI=r132:DI > REG_DEAD r132:DI > 7: r128:SI=r125:DI#0 0>>0x1f > REG_DEAD r125:DI > Failed to match this instruction: > (set (subreg:DI (reg:SI 128 [ x ]) 0) > (zero_extract:DI (reg:DI 132) > (const_int 32 [0x20]) > (const_int 1 [0x1]))) > Successfully matched this instruction: > (set (subreg:DI (reg:SI 128 [ x ]) 0) > (and:DI (lshiftrt:DI (reg:DI 132) > (const_int 31 [0x1f])) > (const_int 4294967295 [0xffffffff]))) > allowing combination of insns 20 and 7 > > The problem should be fixed in another case? Please advice. You should not change the expected counts to what is currently generated. What is currently generated is sub-optimal. It all starts with those zero_extracts, which are always bad for us -- it is a harder to manipulate representation of a limited subset of more basic operations we *do* have. And combine and simplify can handle the more general and simpler formulation just fine. Ideally combine would not try to use *_extract at all if this is not used in the machine description (compare to rotatert for example, a similarly redundant operation). But it currently needs it as intermediate form, untangling this all is quite a bit of work. These testcases (all the rl* ones) should have a big fat comment explaining what the expected, wanted code is. This was easier to do originally, when I actually tested all 65536 possibly combinations, because the expected counts were more "regular" numbers. But this is too slow to test in normal testsuite runs :-) It is wrong to pretend the current state makes the wanted code, these testcases are meant to show exactly when we make suboptimal machine code :-) Segher