From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 341FC3835431 for ; Mon, 7 Jun 2021 13:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 341FC3835431 Received: by mail-ed1-x529.google.com with SMTP id w21so20232287edv.3 for ; Mon, 07 Jun 2021 06:19:46 -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=gXOC3eL8HnBugDBBOlw7kkhhsPcGDQVho2tEZnyWR+s=; b=rH3wEqtMEeSP5dKWsEG+8zI2CKVpJGOF+Oyheo5k0dzcHAePdWHes5rjmnoC7CajoA 7yWNKDpZd+QDZh5aq7iyNPooXxMoyBddqem9V9u2rA6MRHMb8emcGcKssT3mbqIlBmzp qjfjHqUUV8s3uOfCgk0aLDhqB1a5E2a4vPpXO6o6kZOMeayNtXztCV8T9HjED5NEPdgl SVhovvHjjsSLA6xCDQD3LF0v8sqxFcU7RTP0PgKMvHyKhrtlZ1Xikxqw11rKHE0aW6Nj gX7ik5Tj+LtS66CtqVgLJI52WSI9YC3bq7AAjwJ3pOwinf4vs+zDrn2YIMMaIKMGkTN7 yzVQ== X-Gm-Message-State: AOAM530XO9nrIbq0daB4ZwHwAlQxLp1/Q/gqjQQyotId4UtA5yngyjVA 9+crHpQsIyzTkpnnkO6lgaQ99+wHrGPlEI6oQEE= X-Google-Smtp-Source: ABdhPJzctrPAJIqoVeT6NdBriKgsxpCxKzYFUXor0Zni4oJjlcD4qiS89LwW9uiabRC5zWIK4UxV4nSshqVqP1Jrzb8= X-Received: by 2002:aa7:dd81:: with SMTP id g1mr19856806edv.274.1623071985199; Mon, 07 Jun 2021 06:19:45 -0700 (PDT) MIME-Version: 1.0 References: <1cd39bc6-6ed6-34ad-856a-e039a01838b3@hippo.saclay.inria.fr> In-Reply-To: From: Richard Biener Date: Mon, 7 Jun 2021 15:19:34 +0200 Message-ID: Subject: Re: [PATCH] Simplify (view_convert ~a) < 0 to (view_convert a) >= 0 [PR middle-end/100738] To: Hongtao Liu Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.0 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 13:19:56 -0000 On Mon, Jun 7, 2021 at 9:02 AM Hongtao Liu via Gcc-patches wrote: > > On Mon, Jun 7, 2021 at 2:22 PM Hongtao Liu wrote: > > > > 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. > And tree_nop_conversion_p also doesn't handle vector types with > different element numbers. > Shouldn't v4si --> v16qi a nop conversion for all targets? It's a conversion with semantics, like v4si + V_C_E (v16qi) doesn't make sense when you strip the V_C_E as you'll get v4si + v16qi. We don't consider those a nop conversion. Richard. > > > > 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 > > > > -- > BR, > Hongtao