From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id F3D29393A400 for ; Wed, 19 May 2021 11:29:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F3D29393A400 Received: by mail-pl1-x634.google.com with SMTP id p6so6842968plr.11 for ; Wed, 19 May 2021 04:29:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aFtw9ADKmun8ICsFuSEktIAoZdbvNIg0NbSsU8LyU14=; b=F0ny0UAD1ru+gmeXE3IPLpE07D1wU2fL/SaNsIX+/7NZIl2DnVXcu4WzErny6M0CWn gqLNV7SWREs1CUw9QBGEMwwty/mEa+VcIOujz1YvczrC9AdPy328dqHMsTzcUoBfnSQd n/7wWs9hnazm/pFyPNy8xfx6BgS+LPQM6c84pWJElC2B9o7R+IgWJJ463w2TOqOmzvD+ Adi6rO4P5FxYcft6hj6ItA8HsbBpVNo2hvnjP9GKnujrciIanRshFraAWDPMjb4vZgpp Dz61bcUimXOGiqwJgPdaF6+352nlo27f94f+cSYTVrShfsaH2p4oi8bprICBupEdkI7S Ljuw== X-Gm-Message-State: AOAM532ivErQmL4CAJ6X++oN7EY+dRk06JVH3NBRCn9bS4NNsXdC880m OVibHG3kzLVf9HMjjLr95GL5k3MgY8pZImtwRJYwLA== X-Google-Smtp-Source: ABdhPJyfPvO1ROoYQG8hBgoH1F17U3Ped88FDQEoWIFl+NpYNB2D8hUl2gd9yuqPV8oV2EDuTLzrnDPPMA+t9aKc1dM= X-Received: by 2002:a17:902:ed82:b029:ef:48c8:128e with SMTP id e2-20020a170902ed82b02900ef48c8128emr10428783plj.72.1621423750817; Wed, 19 May 2021 04:29:10 -0700 (PDT) MIME-Version: 1.0 References: <20210518074202.GL1179226@tucnak> <20210519090919.GT1179226@tucnak> <20210519095136.GU1179226@tucnak> In-Reply-To: From: Christophe Lyon Date: Wed, 19 May 2021 13:29:00 +0200 Message-ID: Subject: Re: [PATCH] phiopt: Simplify (X & Y) == X -> (X & ~Y) == 0 even in presence of integral conversions [PR94589] To: Richard Biener Cc: Jakub Jelinek , gcc Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 19 May 2021 11:29:13 -0000 On Wed, 19 May 2021 at 13:13, Richard Biener wrote: > > On Wed, 19 May 2021, Jakub Jelinek wrote: > > > On Wed, May 19, 2021 at 11:09:19AM +0200, Jakub Jelinek via Gcc-patches wrote: > > > On Wed, May 19, 2021 at 10:15:53AM +0200, Christophe Lyon via Gcc-patches wrote: > > > > After this update, the test fails on arm and aarch64: according to the > > > > logs, the optimization is still performed 14 times. > > > > > > Seems this is because > > > if (change > > > && !flag_syntax_only > > > && (load_extend_op (TYPE_MODE (TREE_TYPE (and0))) > > > == ZERO_EXTEND)) > > > { > > > tree uns = unsigned_type_for (TREE_TYPE (and0)); > > > and0 = fold_convert_loc (loc, uns, and0); > > > and1 = fold_convert_loc (loc, uns, and1); > > > } > > > in fold-const.c adds on these targets extra casts that prevent the > > > optimizations. > > > > This patch seems to fix it (but I don't have an easy way to test on aarch64 > > or arm on the trunk and 11 branch would need numerous backports). > > OK if somebody manages to test on arm/aarch64. > I confirm it fixes the problem on arm. (aarch64 in progress) Thanks! > Richard. > > > 2021-05-19 Jakub Jelinek > > > > PR tree-optimization/94589 > > * match.pd ((X & Y) == X -> (X & ~Y) == 0): Simplify even in presence > > of integral conversions. > > > > --- gcc/match.pd.jj 2021-05-15 10:10:28.000000000 +0200 > > +++ gcc/match.pd 2021-05-19 11:34:42.130624557 +0200 > > @@ -4769,6 +4769,16 @@ (define_operator_list COND_TERNARY > > (simplify > > (cmp:c (bit_and:c @0 @1) @0) > > (cmp (bit_and @0 (bit_not! @1)) { build_zero_cst (TREE_TYPE (@0)); })) > > + (simplify > > + (cmp:c (convert@3 (bit_and (convert@2 @0) INTEGER_CST@1)) (convert @0)) > > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) > > + && INTEGRAL_TYPE_P (TREE_TYPE (@2)) > > + && INTEGRAL_TYPE_P (TREE_TYPE (@3)) > > + && TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@0)) > > + && TYPE_PRECISION (TREE_TYPE (@3)) > TYPE_PRECISION (TREE_TYPE (@2)) > > + && !wi::neg_p (wi::to_wide (@1))) > > + (cmp (bit_and @0 (convert (bit_not @1))) > > + { build_zero_cst (TREE_TYPE (@0)); }))) > > > > /* (X | Y) == Y becomes (X & ~Y) == 0. */ > > (simplify > > > > > > Jakub