From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 8E24B38582A7 for ; Wed, 3 Aug 2022 22:39:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E24B38582A7 Received: by mail-pg1-x52d.google.com with SMTP id d7so13314654pgc.13 for ; Wed, 03 Aug 2022 15:39:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=7Dt/mtzbCJe55HVFwrxjUkPksxT4Em9lb2zXs3CXxX4=; b=LCOVdmkzRk+PUESfrQfL26T2nVJJ+5nysTolFt+1gr6CmLsPoeOsKKVfMHd/rcjEuX Pig9o2lYJ2fqxt9T80RWNUsfXKIH50Sfc0MtyEZ383GLBygShrVjf4A4sEPcX9VLRt8x 83HnUFcXEpXQAXmN+HSdphNc/wEDe5uV5eHAthWiYrmExezgSM1a+qnSZyQ9jxznUw3i 8a++z3+Za+0Vhn20BSdyk64CUrm8y9zaKnjoULB2XBmT5U4TIY4RNBfatGWp7nt2E0JU 1IaBKdB8qexin57rjLzQPtOy3DBs4GxRSUyIvoNHQwfGK5aHPhNob5t/foE0tc0SMpyI l5rg== X-Gm-Message-State: ACgBeo0OHjQgMPLSqRuznicrJZTxBimSxu7Ctx6K6Ir5yJs+3hAh+LPL cStYyV9bGvGxppHOMlOPTWhW9++yVL8= X-Google-Smtp-Source: AA6agR6E3+kxx+tv3JJnunHKJ3+Jls5HpaHT3rakUe9hAt27cZE3BfuczFWp/rqorp6ct5gpzM4evg== X-Received: by 2002:a63:6948:0:b0:41c:9c35:a047 with SMTP id e69-20020a636948000000b0041c9c35a047mr3894514pgc.68.1659566384763; Wed, 03 Aug 2022 15:39:44 -0700 (PDT) Received: from [172.31.0.204] (c-73-98-188-51.hsd1.ut.comcast.net. [73.98.188.51]) by smtp.gmail.com with ESMTPSA id q38-20020a635c26000000b00419acadde52sm11604558pgb.46.2022.08.03.15.39.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Aug 2022 15:39:44 -0700 (PDT) Message-ID: <527a41b9-92a1-e662-da89-3176b77524fe@gmail.com> Date: Wed, 3 Aug 2022 16:39:42 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] match.pd: Add bitwise and pattern [PR106243] Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <20220803191014.2284344-1-sfeifer@redhat.com> From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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: Wed, 03 Aug 2022 22:39:48 -0000 On 8/3/2022 2:44 PM, Prathamesh Kulkarni via Gcc-patches wrote: > On Thu, 4 Aug 2022 at 00:41, Sam Feifer via Gcc-patches > wrote: >> This patch adds a new optimization to match.pd. The pattern, -x & 1, >> now gets simplified to x & 1, reducing the number of instructions >> produced. > Hi Sam, > No comments on patch, but wondering if we can similarly add another pattern to > simplify abs(x) & 1 -> x & 1 ? > Currently we don't appear to do it on GIMPLE: > > __attribute__((noipa)) > int f1 (int x) > { > return __builtin_abs (x) & 1; > } > > .optimized dump shows: > _1 = ABS_EXPR ; > _3 = _1 & 1; > return _3; > > altho combine simplifies it to x & 1 on RTL, resulting in code-gen: > f1: > and w0, w0, 1 > ret Doesn't the abs(x) & mask simplify to x & mask for any mask where the sign bit of x is off -- including cases where mask isn't necessarily a compile-time constant, but we have range data which allows us to know that x's sign bit is off in mask. jeff