From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 6557A3858430 for ; Wed, 24 May 2023 08:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6557A3858430 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-x236.google.com with SMTP id 38308e7fff4ca-2af290cf9b7so8557691fa.3 for ; Wed, 24 May 2023 01:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684918620; x=1687510620; 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=0xm1Bx02qJ0F+aG2bBLoKTZemHVqhAs/iPvp/ZBrun4=; b=is5YPYlDZZJY1djOp7hM4TPlLYzwOOIFHOlP9d9jY0O6p7k27HGvveWsbjgmdOimWF m05jPQsM38CcKd7ioMfhpR7W7wMVzrZ8Dxdj6h1+3Cf9zbz0Avn7brVHi85AEPO41q+6 ifwWi1xfH0MSgHFm6mLZygmhZSRrO3Fv7ehJNDpNvoi/xv6SpBYTNknH8VclfcylTbVB 2OXHrba4eKXhp5H3TANeRFYY8YWzvruoqyQk6Nrdw1zSzliuh2si7orNFWbknjVb58GA RHBG9sCuMdZj+Jmt5rTns/peplSsYI4jRsRvDsyPxmIl6PygUb0/gkmzyXe11ENpKHRt rpog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684918620; x=1687510620; 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=0xm1Bx02qJ0F+aG2bBLoKTZemHVqhAs/iPvp/ZBrun4=; b=gzFLYYipSqIzZcpE5AnVz0kiaASy+bq2jwZ3T3201dt45KEJKVElSYW35LUWvdTxbq 8wbDCd12uA5LXnQ4W7JpPPhM8JBkUwVB3VBfjqTGfplWhiq+j5gCTCiMjWTJ9kHTMPBM CZBBcS3rmmp5QaW1OFRcd5b5CnLf66M+guJcU6t6akByfh1K+ehRFjcOu6RlbDk7Zu5O bo+uafbCLoDbcwrZSSvgyh74isI3BSzEHVEKLY8ybGx4/e9mKGWoTmpbSyyYpHfQotmX bt1CzkZJATawK0u6UrbZEOnxpaPOddD1hRz3n7GOonVO69EAk2OEIroBJ+qKL7x7fBM3 VnkQ== X-Gm-Message-State: AC+VfDx/9IEtjx7Haw3LYn/cEUXNAiBqbi173lYw2JbzVf8GGG8OwZIs 2+HSoru261Ru70EKcydubN5IWIy5L73Zp48uHpxaIp4D X-Google-Smtp-Source: ACHHUZ7b/W/d8lG6cuhZEdVnwQT+1ltbCxBCPZY4YLayKrJgVlaIOmA/cT0pKaM+JGlip9NzGMt/C4kO+ZwYUlxz9Bg= X-Received: by 2002:a2e:3506:0:b0:2a8:ba49:a811 with SMTP id z6-20020a2e3506000000b002a8ba49a811mr6073967ljz.25.1684918619373; Wed, 24 May 2023 01:56:59 -0700 (PDT) MIME-Version: 1.0 References: <075901d98da4$a1fc4dc0$e5f4e940$@nextmovesoftware.com> In-Reply-To: <075901d98da4$a1fc4dc0$e5f4e940$@nextmovesoftware.com> From: Richard Biener Date: Wed, 24 May 2023 10:54:53 +0200 Message-ID: Subject: Re: [PATCH] PR middle-end/109840: Preserve popcount/parity type in match.pd. To: Roger Sayle Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.4 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 Tue, May 23, 2023 at 8:30=E2=80=AFPM Roger Sayle wrote: > > > PR middle-end/109840 is a regression introduced by my recent patch to > fold popcount(bswap(x)) as popcount(x). When the bswap and the popcount > have the same precision, everything works fine, but this optimization als= o > allowed a zero-extension between the two. The oversight is that we need > to be strict with type conversions, both to avoid accidentally changing > the argument type to popcount, and also to reflect the effects of > argument/return-value promotion in the call to bswap, so this zero extens= ion > needs to be preserved/explicit in the optimized form. > > Interestingly, match.pd should (in theory) be able to narrow calls to > popcount and parity, removing a zero-extension from its argument, but > that is an independent optimization, that needs to check IFN_ support. > Many thanks to Andrew Pinski for his help/fixes with these transformation= s. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=3Dunix{-m32} > with no new failures. Ok for mainline? OK. Thanks, Richard. > > 2023-05-23 Roger Sayle > > gcc/ChangeLog > PR middle-end/109840 > * match.pd : Preserve zero-extension when > optimizing popcount((T)bswap(x)) and popcount((T)rotate(x,y)) as > popcount((T)x), so the popcount's argument keeps the same type. > : Likewise preserve extensions when > simplifying parity((T)bswap(x)) and parity((T)rotate(x,y)) as > parity((T)x), so that the parity's argument type is the same. > > gcc/testsuite/ChangeLog > PR middle-end/109840 > * gcc.dg/fold-parity-8.c: New test. > * gcc.dg/fold-popcount-11.c: Likewise. > > > Thanks in advance, and apologies for any inconvenience. > Roger > -- >