From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by sourceware.org (Postfix) with ESMTPS id 22C09383B831 for ; Mon, 7 Jun 2021 06:17:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22C09383B831 Received: by mail-vs1-xe32.google.com with SMTP id z15so8302294vsn.13 for ; Sun, 06 Jun 2021 23:17:38 -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; bh=oG4m/E1C14FoK9h23tzoMkILXtouUgLjArUxHJ0tulQ=; b=H3rHCo9u2D9TzWc3NwJBkoYxdX32PkdcsGzcZaR4ll6+8/9CT/R8X76FGAHvBFYeXP 5MKn8s16wqS+HieARnoRtiX69QUFAwM4aOMdqCTnqw+sUmivjAjsv1wLEbZYvdopBUZW OCDh1dn+sMLgpWe+k9iB/Zk+UgP0c9eGd45Qh42DOAUS4Qgj1bayAEElCKrk/WoATPQb M8HBXZjuTuKMRJHqkxltWQZ8o8uloKGa+l5tc8v0dgaeTMcLIYmksL9x991YZsTV3/jK oNWxWS0ZdC13AJsJU4ujjrCH2PYA9SNSHzGPeA8l7pAO3uXOrF+Qt/Be3LRbFKB89DO8 7l3A== X-Gm-Message-State: AOAM533Hu3X7RKt5SV3CSh0UoykIIMAzmMEdFfgdM/N2nePqxpgYE81k yjfm2i3SmogsIbs52sVzrNSSoeGmoXO6dpaGNrc4YKhR1xr6gw== X-Google-Smtp-Source: ABdhPJyocNyMjJCgIz+h7//869n/K5cVf1D3eTxyUkOonbdYM592SfC4VaxUOAt3qcwNDpUgUsuO8UWy+G5hgSY1Sgw= X-Received: by 2002:a67:c904:: with SMTP id w4mr7975714vsk.48.1623046657497; Sun, 06 Jun 2021 23:17:37 -0700 (PDT) MIME-Version: 1.0 References: <1cd39bc6-6ed6-34ad-856a-e039a01838b3@hippo.saclay.inria.fr> In-Reply-To: <1cd39bc6-6ed6-34ad-856a-e039a01838b3@hippo.saclay.inria.fr> From: Hongtao Liu Date: Mon, 7 Jun 2021 14:22:30 +0800 Message-ID: Subject: Re: [PATCH] Simplify (view_convert ~a) < 0 to (view_convert a) >= 0 [PR middle-end/100738] To: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.3 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 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: Mon, 07 Jun 2021 06:17:48 -0000 On Fri, Jun 4, 2021 at 4:18 PM Marc Glisse wrote: > > On Fri, 4 Jun 2021, Hongtao Liu via Gcc-patches wrote: > > > On Tue, Jun 1, 2021 at 6:17 PM Marc Glisse wrote: > >> > >> On Tue, 1 Jun 2021, Hongtao Liu via Gcc-patches wrote: > >> > >>> Hi: > >>> This patch is about to simplify (view_convert:type ~a) < 0 to > >>> (view_convert:type a) >= 0 when type is signed integer. Similar for > >>> (view_convert:type ~a) >= 0. > >>> Bootstrapped and regtested on x86_64-linux-gnu{-m32,}. > >>> Ok for the trunk? > >>> > >>> gcc/ChangeLog: > >>> > >>> PR middle-end/100738 > >>> * match.pd ((view_convert ~a) < 0 --> (view_convert a) >= 0, > >>> (view_convert ~a) >= 0 --> (view_convert a) < 0): New GIMPLE > >>> simplification. > >> > >> We already have > >> > >> /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ > >> (for cmp (simple_comparison) > >> scmp (swapped_simple_comparison) > >> (simplify > >> (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1) > >> (if (single_use (@2) > >> && (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST)) > >> (scmp @0 (bit_not @1))))) > >> > >> Would it make sense to try and generalize it a bit, say with > >> > >> (cmp (nop_convert1? (bit_not @0)) CONSTANT_CLASS_P) > >> > >> (scmp (view_convert:XXX @0) (bit_not @1)) > >> > > Thanks for your advice, it looks great. > > And can I use *view_convert1?* instead of *nop_convert1?* here, > > because the original case is view_convert, and nop_convert would fail > > to simplify the case. > > Near the top of match.pd, you can see > > /* With nop_convert? combine convert? and view_convert? in one pattern > plus conditionalize on tree_nop_conversion_p conversions. */ > (match (nop_convert @0) > (convert @0) > (if (tree_nop_conversion_p (type, TREE_TYPE (@0))))) > (match (nop_convert @0) > (view_convert @0) > (if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@0)) > && known_eq (TYPE_VECTOR_SUBPARTS (type), > TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0))) > && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@0)))))) > Oh, it's restricted to the same number of elements which is not the case i tested. That's why nop_convert failed to simplify the case. Guess we can define another nop1_convert to handle vector types with different number of elements, but still tree_nop_convertion_p? > So at least the intention is that it can handle both NOP_EXPR for scalars > and VIEW_CONVERT_EXPR for vectors, and I think we alread use it that way > in some places in match.pd, like > > (simplify > (negate (nop_convert? (bit_not @0))) > (plus (view_convert @0) { build_each_one_cst (type); })) > > (simplify > (bit_xor:c (nop_convert?:s (bit_not:s @0)) @1) > (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) > (bit_not (bit_xor (view_convert @0) @1)))) > > (the 'if' seems redundant for this one) > > (simplify > (negate (nop_convert? (negate @1))) > (if (!TYPE_OVERFLOW_SANITIZED (type) > && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@1))) > (view_convert @1))) > > etc. > > > At some point this got some genmatch help, to handle '?' and numbers, so I > don't remember all the details, but following these examples should work. > > -- > Marc Glisse -- BR, Hongtao