From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id C53B73858C41 for ; Mon, 24 Jul 2023 07:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C53B73858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b701e41cd3so55477821fa.3 for ; Mon, 24 Jul 2023 00:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690182997; x=1690787797; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LaJ8iYOcAKTJ9Nb8MLbfjzmnSIlIlAX99TpBRg+emOM=; b=DTPgIL3j9jaa+g9WL8EfOVGfAuolXodKAaJCjz0ruVeXVNw+UpAcIekm3o6EY6t9pC eomBMmpxmIbVpPwPSeTNSZGmbzbIeoUFbwExc/p+cXsHK7Uq+f6KoDswbX79xCQp1+JJ 8slPocTlxepTdTVq4Mz7JbIcCRMf2Usw8bFbkbCCRNdXewVYuw9epgTOUg1jCXDPQoKQ HukibC7GYH6YrcyKe+VKDPrdc6R5KZQ7F833NUDFPMQx2r0C+otajj1pONiJaZC1WNGh cOXF6cvLQYzfomhqk86YTy9g36C/VzoPwqK3wKUFq3XCy9tQTlHAYaX7g6TVpkEySbFE CfEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690182997; x=1690787797; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LaJ8iYOcAKTJ9Nb8MLbfjzmnSIlIlAX99TpBRg+emOM=; b=QWd1fXMS6fRlNa+AySNzGCOfTHop0dT9RdJg+BRaw80nNJ1PnVNuQufapDZuG4KjkV IFf8MtsFMRunVlt+Z5alKMN+EsqFhQq9YLvz/co01aHufUEu1yuue8ClfCTAw7GuyNy5 VYeDOPaDp7ZG4jHQ+wfgQYO9+oDCC64XyeO5DCW6a3xXSGmqJwz+d2vPRe2MgyJJrZ0b EOhCktMe0SKvXrjvvFRNbVxPLy/es5H01d1ywXHfczXcwmQX8qVi44p42VU4pifmCN3C J4xaa7Q97OCDQ1OC7QOcFapP4vaL0qP3QeHICe2AqdBlYxgP5oHbjF0sTLiLyxXOrfg9 JJ5g== X-Gm-Message-State: ABy/qLbz7DrZ3Zzn0wkwAi5zPMaf/tlW+D8bH+dnrSSepPVVGNxrjhgU h9CNUOUTslql2tHxuZrIBpi/NGUvnvtDL7sxq2I= X-Google-Smtp-Source: APBJJlGKtJs5QfqYAW5M0D/52fk79t89gqXMc06Qd6C1tlcTc39ODOJimuVWFNfFlRpOi0LhqgrWtl7A69n86urGBks= X-Received: by 2002:a2e:81d8:0:b0:2b7:117:e54 with SMTP id s24-20020a2e81d8000000b002b701170e54mr5565237ljg.4.1690182996740; Mon, 24 Jul 2023 00:16:36 -0700 (PDT) MIME-Version: 1.0 References: <20230721150851.94504-1-drross@redhat.com> <6acebf98-5165-2c0c-7dea-0c148b7034cd@gmail.com> In-Reply-To: <6acebf98-5165-2c0c-7dea-0c148b7034cd@gmail.com> From: Richard Biener Date: Mon, 24 Jul 2023 09:16:24 +0200 Message-ID: Subject: Re: [PATCH] match.pd: Implement missed optimization (x << c) >> c -> -(x & 1) [PR101955] To: Jeff Law Cc: Andrew Pinski , Drew Ross , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Sat, Jul 22, 2023 at 8:09=E2=80=AFAM Jeff Law via Gcc-patches wrote: > > > > On 7/21/23 11:27, Andrew Pinski via Gcc-patches wrote: > > On Fri, Jul 21, 2023 at 8:09=E2=80=AFAM Drew Ross via Gcc-patches > > wrote: > >> > >> Simplifies (x << c) >> c where x is a signed integral type of > >> width >=3D int and c =3D precision(type) - 1 into -(x & 1). Tested suc= cessfully > >> on x86_64 and x86 targets. > > > > Thinking about this some more, I think this should be handled in > > expand rather than on the gimple level. > > It is very much related to PR 110717 even. We are basically truncating > > to a signed one bit integer and then sign extending that across the > > whole code. > But why defer it to expand? This idiom is going to generate a -1,0 > result which is definitely interesting from a further simplification > standpoint. It's not 'simpler' so it would be a canonicalization. We talked about providing a SEXT_EXPR at some point (sign-extend from constant bit N). Another canonicalization to existing ops would be (convert (convert:sbool @0)) where sbool is a 1-bit precision signed type. I think that's a better canonicalization than -(x & 1)? For zero-extensions we canonicalize such a conversion seque= nce to x & const-mask. For sign-extensions there's no single operation representation. Richard. > > Jeff