From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id E0B2E3898516 for ; Wed, 19 May 2021 12:20:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E0B2E3898516 Received: by mail-pl1-x62e.google.com with SMTP id a11so6928396plh.3 for ; Wed, 19 May 2021 05:20:09 -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=c6aEGglnEjaihYvLvZu4UJxlVc89dFn2IPhPNzRk/e4=; b=nw9QeXpOTqFIAQaKmY80g2lj3oHHMHoVFKjc5kJJ+yNu7bZ1+B769MtqvGcPrYCXt1 M26Nett9XWzkPXJfv/EBbxbuO1HZkgpWGOFU3/lqMji5zZhl4F4nyToVArUSqQPBXiU5 mgq/jD3t6Wq6NTfie/bePoFTNFG2zrwXtZ9nR1B1S3HNmajb5ep/NrsxmG4uhabZpGja 7i6nBEYAWIcEEh+0nz+/r6x+seyeiy62smL8VJYSemESw0xpiOYjjK2Pr+r3LTjXqg7p BbQ9G4x2YkQqole7msR2wsw4MVtWO7CuE2OgWP1xf5yAkvh6nD+mVcEZarMTLl2j3c4u 5b8g== X-Gm-Message-State: AOAM532oNUJbTeLI2EUfQBIKlLuH1kPzeaLJYnZ+BKcqPvK+MK7/gukv gNsLG6eSrqliuwUbLyhNkuQaDSm5AoC/yd/X9tKh1Q== X-Google-Smtp-Source: ABdhPJxnWvsP9TXFq13VIx5g/GFHNYQ2rjL1NFXTdQzjh68IPXKjcpTuCWVPW4tREZxQErnFSVQhuAaZ4DB2BuChF08= X-Received: by 2002:a17:90a:9d88:: with SMTP id k8mr10890599pjp.64.1621426808766; Wed, 19 May 2021 05:20:08 -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 14:19:58 +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.3 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 12:20:12 -0000 On Wed, 19 May 2021 at 13:29, Christophe Lyon wrote: > > 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) > And aarch64 is OK too. > 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