From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by sourceware.org (Postfix) with ESMTPS id 6EB1C3857346 for ; Mon, 2 May 2022 11:49:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6EB1C3857346 Received: by mail-vk1-xa33.google.com with SMTP id x9so6494365vke.4 for ; Mon, 02 May 2022 04:49:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mTsdwH8hISipIpQ/qYtilx6kppBjXK81s/wHH7wXJuU=; b=X5U5kFgeJ/6uZhOIUHVRbL4ongS6nENaowecNEKCyIfhMDSiWsa5o8aQHHTNZNheE1 MmM+ATc7EuYpiYRfa9XofyzLmXgeLjN6nH3q+PxOsUp4wpU7FWLd+BXQO7JCJ8VCLhPf TQw6HqD4jF4KcNFunuL48XJPj9cbra2Q08Iq6lr/XzzTTD8KPJde1r9K2x+EvHX1oCi7 CLSNidVUxKzFjl6sgBFHtzRpBAjALX4XUM22dNWmeb61OnCqZAsBto189XeVbnLSK8VC A33UlvEx6Dex2kWvb4vskUc0c/n9IkhF6lmgW3PBeqPBdQalbRVfLejDbQuMVQy2rnbD vmnA== X-Gm-Message-State: AOAM531ZPZLsZkv+qcJIO3i5/A7uRkI7czx7PMHNUtTq8Vb+180J1Ypg WvN8TPIVe8ClC8XBb/pszsJVSLtqzTa7yL3fDcM4h+i9 X-Google-Smtp-Source: ABdhPJwg7XKQUoA8DR+eYjKBCw6YDQLizraGz4ddIYeCHVsr21cqCnrs0kYKs9E+17dei7NNUU9Vv3LLMsmdm2luZto= X-Received: by 2002:a1f:aa16:0:b0:345:df50:5f89 with SMTP id t22-20020a1faa16000000b00345df505f89mr3055482vke.21.1651492183765; Mon, 02 May 2022 04:49:43 -0700 (PDT) MIME-Version: 1.0 References: <005401d81749$b1d77ad0$15867070$@nextmovesoftware.com> In-Reply-To: <005401d81749$b1d77ad0$15867070$@nextmovesoftware.com> From: Richard Biener Date: Mon, 2 May 2022 13:49:32 +0200 Message-ID: Subject: Re: [PATCH] PR tree-optimization/102950: Improved EVRP for signed BIT_XOR_EXPR. To: Roger Sayle Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 02 May 2022 11:49:45 -0000 On Tue, Feb 1, 2022 at 9:57 AM Roger Sayle wrote: > > > This patch fixes PR tree-optimization/102950, which is a P2 regression, > by providing better range bounds for BIT_XOR_EXPR, BIT_AND_EXPR and > BIT_IOR_EXPR on signed integer types. In general terms, any binary > bitwise operation on sign-extended or zero-extended integer types will > produce results that are themselves sign-extended or zero-extended. > More precisely, we can derive signed bounds from the number of leading > redundant sign bit copies, from the equation: > clrsb(X op Y) >= min (clrsb (X), clrsb(Y)) > and from the property that for any (signed or unsigned) range [lb, ub] > that clrsb([lb, ub]) >= min (clrsb(lb), clrsb(ub)). > > These can be used to show that [-1, 0] op [-1, 0] is [-1, 0] or that > [-128, 127] op [-128, 127] is [-128, 127], even when tracking nonzero > bits would result in VARYING (as every bit can be 0 or 1). This is > equivalent to determining the minimum type precision in which the > operation can be performed then sign extending the result. > > One additional refinement is to observe that X ^ Y can never be > zero if the ranges of X and Y don't overlap, i.e. X can't be equal > to Y. > > Previously, the expression "(int)(char)a ^ 233" in the PR was considered > VARYING, but with the above changes now has the range [-256, -1][1, 255], > which is sufficient to optimize away the call to foo. > > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check with no new failures. Ok for mainline? OK for trunk. Thanks, Richard. > > 2022-02-01 Roger Sayle > > gcc/ChangeLog > PR tree-optimization/102950 > * range-op.cc (wi_optimize_signed_bitwise_op): New function to > determine bounds of bitwise operations on signed types. > (operator_bitwise_and::wi_fold): Call the above function. > (operator_bitwise_or::wi_fold): Likewise. > (operator_bitwise_xor::wi_fold): Likewise. Additionally, the > result can't be zero if the operands can't be equal. > > gcc/testsuite/ChangeLog > PR tree-optimization/102950 > gcc.dg/pr102950.c: New test case. > gcc.dg/tree-ssa/evrp10.c: New test case. > > > Thanks in advance (and Happy Chinese New Year), > Roger > -- >