From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.221]) by sourceware.org (Postfix) with ESMTPS id DAE253858284 for ; Wed, 24 Jan 2024 15:49:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAE253858284 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DAE253858284 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.221 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706111365; cv=pass; b=HKqzPMOxg27PJWRScJiR5T3U7rJ+fn62Co8kspWzqw8fyKL0zjyBObK5eOSTT1DpbIyBS8tKr9bq6Pc8oTmiCbAEGFFAVtdNA26W1+F10cjFDfeYAMd/6PnZMEw5JSPsdYhqkzyVLJOJIJpW6uVcybMiN7IM8KarVpaJOc63SL0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706111365; c=relaxed/simple; bh=2zDU/XHol6dvDap59QN1SSREYoojoRK1eBxHvikiE1A=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=oeUsakID2yb15Im5f3iRi5XKwzGWZucjGn8YKqrVR+w/1HWQGUZ86yLnAfy9/9oPa53nF7EzMtFEOjMHmWMZjRMlC2beVmTFUsM4pBbTQhdj+2yFrKVvefcn+AaPWURG/ZK1rL+GVt27wJ8w+DpyH+X4uW6Tc49rkWCUefPsDBg= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1706111359; cv=none; d=strato.com; s=strato-dkim-0002; b=E7LS+7+XHzFRBuOrJz2JWQQywlvL0YaupQ6EwN/anZO4U13xBfGbd+8pSsrnjYMVWk hHTDkTWsvTMynwwDltjm24Ql/Bc3A4dRQxSFIQx3hsdkPa0XmW9GHnH5Yjr+A4S4WZ7H wqf2N8E4I40rMaXq3533tZKWfX+tAqNRlzKAwvtRtngp66wObUF6EIt5a8fZkBAChwRY nzxGfJNvsKVaD6J5g92ChglYY0wJLaAVsH6ZnLNFXQ3B77FX3UAPJ+SwQHJihASkxl9C /OOyatzvAsRJfFIZs64sxkiMmMPncZb99SjkXDFooDSOmzDyOeEYd+gycl9WfDYGDfwD V35g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1706111359; s=strato-dkim-0002; d=strato.com; h=In-Reply-To:From:References:Cc:To:Subject:Date:Message-ID:Cc:Date: From:Subject:Sender; bh=y/VVb557TMMLhm+E02j6Bftq+CTquUQszxV4XONKOa4=; b=eJuKvY4uyiDxz6rc627pQxqd8kDU3i5fE6MH7tVKjo1KRStnPwr9qrF6nrS5iXHdEb 5qjwDFemA8Cd0x9+GR+jBc9bOeITW+HBYNImix45JRqIp7c9RwXByiEsbjCCE0uOU3CP DYeAHgP2LaDWTy3zB2erfYFKXLCKM/BFMmU5g1nlzGdcMMVsCHFGZ9X9OGFPojIiOVVj yxRFCCx3LGihIjws1sToXDwOOdBygzKtYyaJYquzGrAQQ+1izhQhGjEal44F1U2R/mF8 Da5hBj9XfstY0f0AHM6BXnYadmUsm7Kjky+kSAzdp1DIvKIl49Bl/Qir1cvRLkQ9FAYP BQNg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1706111359; s=strato-dkim-0002; d=gjlay.de; h=In-Reply-To:From:References:Cc:To:Subject:Date:Message-ID:Cc:Date: From:Subject:Sender; bh=y/VVb557TMMLhm+E02j6Bftq+CTquUQszxV4XONKOa4=; b=BERa9E7pUqceqbB36X8rnuAAc9TobXjLB5YBCIiYUlP0PJXAngYQ2HL6S9WfNqsSA/ LSrC66rELFByW5kwU0X81f7wmyTxieHsC8ur1hOotKqd3KWMXWD/NC2mzPrZXL6Xxoe+ rZQQolBigJF3FmFJxrZnzYnjo0RnEnZXscikZ22ZBpFpx17jf3BTvwj+s3U+DjM6ruag Q6TxkkLOTaR86KOpa4femVZ1w7+NPfxpwMTDm5rb197ab0zPoWiycpeeOUQnAZ+UeGqU DQsMCNU5RgqoDLN5gN/rLtzKUZLvirZWcIWfd5CjHs7g5VXg84KeM3CDXnev/rcIUYjs 0MXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1706111359; s=strato-dkim-0003; d=gjlay.de; h=In-Reply-To:From:References:Cc:To:Subject:Date:Message-ID:Cc:Date: From:Subject:Sender; bh=y/VVb557TMMLhm+E02j6Bftq+CTquUQszxV4XONKOa4=; b=Y7DBeHT3cTMQTBAiiPxM1ENrRbez5qGZt+xXzEozgd0fnmi1Z+H1/L76lCupuAzSXT 6jJWFPBIROenDdwotjAQ== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkSjsSjq3WhKPVxx3mY" Received: from [192.168.2.102] by smtp.strato.de (RZmta 49.11.2 DYNA|AUTH) with ESMTPSA id Lb68c600OFnI7Sn (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 24 Jan 2024 16:49:18 +0100 (CET) Message-ID: <3ad0a683-e227-4499-bc5a-c08a9b50eb66@gjlay.de> Date: Wed, 24 Jan 2024 16:49:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [middle-end PATCH] Prefer PLUS over IOR in RTL expansion of multi-word shifts/rotates. Content-Language: en-US To: Richard Biener Cc: Roger Sayle , gcc-patches@gcc.gnu.org References: <023501da4a48$320e7540$962b5fc0$@nextmovesoftware.com> <71f8f116-e3b8-4e70-b30a-a4bc042466a2@gjlay.de> From: Georg-Johann Lay In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Am 22.01.24 um 08:45 schrieb Richard Biener: > On Fri, Jan 19, 2024 at 5:06 PM Georg-Johann Lay wrote: >> >> >> >> Am 18.01.24 um 20:54 schrieb Roger Sayle: >>> >>> This patch tweaks RTL expansion of multi-word shifts and rotates to use >>> PLUS rather than IOR for disjunctive operations. During expansion of >>> these operations, the middle-end creates RTL like (X<>C2) >>> where the constants C1 and C2 guarantee that bits don't overlap. >>> Hence the IOR can be performed by any any_or_plus operation, such as >>> IOR, XOR or PLUS; for word-size operations where carry chains aren't >>> an issue these should all be equally fast (single-cycle) instructions. >>> The benefit of this change is that targets with shift-and-add insns, >>> like x86's lea, can benefit from the LSHIFT-ADD form. >>> >>> An example of a backend that benefits is ARC, which is demonstrated >>> by these two simple functions: >> >> But there are also back-ends where this is bad. >> >> The reason is that with ORI, the back-end needs only to operate no >> these sub-words where the sub-mask is non-zero. But for PLUS this >> is not the case because the back-end does not know that intermediate >> carry will be zero. Hence, with PLUS, more instructions are needed. >> An example is AVR, but maybe much more target with multi-word operations >> are affected in a bad way. >> >> Take for example the case with 2 words and a value of 1. >> >> LO |= 1 >> HI |= 0 >> >> can be optimized to >> >> LO |= 1 >> >> but for addition this is not the case: >> >> LO += 1 >> HI +=c 0 ;; Does not know that always carry = 0. > > I wonder if the PLUS can be done on the lowpart only to make this > detail obvious? For AVR, word_mode is HImode, but the hardware has only 8-bit registers. Moreover splitting insns is not wanted or not possible (due to CCmode). Johann >>> unsigned long long foo(unsigned long long x) { return x<<2; } >>> >>> which with -O2 is currently compiled to: >>> >>> foo: lsr r2,r0,30 >>> asl_s r1,r1,2 >>> asl_s r0,r0,2 >>> j_s.d [blink] >>> or_s r1,r1,r2 >>> >>> with this patch becomes: >>> >>> foo: lsr r2,r0,30 >>> add2 r1,r2,r1 >>> j_s.d [blink] >>> asl_s r0,r0,2 >>> >>> unsigned long long bar(unsigned long long x) { return (x<<2)|(x>>62); } >>> >>> which with -O2 is currently compiled to 6 insns + return: >>> >>> bar: lsr r12,r0,30 >>> asl_s r3,r1,2 >>> asl_s r0,r0,2 >>> lsr_s r1,r1,30 >>> or_s r0,r0,r1 >>> j_s.d [blink] >>> or r1,r12,r3 >>> >>> with this patch becomes 4 insns + return: >>> >>> bar: lsr r3,r1,30 >>> lsr r2,r0,30 >>> add2 r1,r2,r1 >>> j_s.d [blink] >>> add2 r0,r3,r0 >>> >>> >>> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap >>> and make -k check, both with and without --target_board=unix{-m32} >>> with no new failures. Ok for mainline? >>> >>> >>> 2024-01-18 Roger Sayle >>> >>> gcc/ChangeLog >>> * expmed.cc (expand_shift_1): Use add_optab instead of ior_optab >>> to generate PLUS instead or IOR when unioning disjoint bitfields. >>> * optabs.cc (expand_subword_shift): Likewise. >>> (expand_binop): Likewise for double-word rotate. >>> >>> >>> Thanks in advance, >>> Roger