From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id BEFA5383943B for ; Mon, 16 Aug 2021 06:22:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BEFA5383943B Received: by mail-ej1-x629.google.com with SMTP id bt14so13984902ejb.3 for ; Sun, 15 Aug 2021 23:22:30 -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=6ZRttJYdm2i6AeTunaIvQ2CfJCjoCj8FZRhurNqkIDs=; b=N8cF5dingqGYbuo+kXeiOvoTm+aNjTokh4TxpTJqjPSQyoYxXjl7g+MduYAUqsGtgJ FNixrPgDA13KMcvZqqMrNhXV9auPqvMs8xoGV4hOrK6wN+zee3D5OBePquNA5E9FqEjN Cmv+8NBb0DXZsX7Zdbr+NUh1Z4Lb1kP10aBEwUmlAapEzQmCIC6lcbHBmO/xJoMjHTqt PhaZEHq02EAClvgJZqRJyi/Ra1WYLobT9GSri8d276e4JYGxQt7qiAJbwYLXmOXM3Wds r+XHxT+rhJlCf8Rn38qEL98mbfX4B2J488+gNHi4NbldfGzzv3XGqchDa3LnA1lYzHk0 z4Hw== X-Gm-Message-State: AOAM530vH6FCFvQ/naA9zWofgzOEE/Y2pBN7emMqlqyus8Upeajh1paV 2huy3RXX+t1sGowPusWS+EKFNCzjNdHytUR75gg= X-Google-Smtp-Source: ABdhPJw8bQvxRVO8u7aPZSx3hLrfY+/Fde8sI5F+ihwqQBTEx/tVC1QnzHo/TMFE6RY8f/qd5i9DHwePRa2nSfoZ9gg= X-Received: by 2002:a17:906:4c89:: with SMTP id q9mr14548652eju.118.1629094949822; Sun, 15 Aug 2021 23:22:29 -0700 (PDT) MIME-Version: 1.0 References: <1628900361-27676-1-git-send-email-apinski@marvell.com> In-Reply-To: <1628900361-27676-1-git-send-email-apinski@marvell.com> From: Richard Biener Date: Mon, 16 Aug 2021 08:22:19 +0200 Message-ID: Subject: Re: [PATCH 1/2] Add gimple_truth_valued_p to match.pd and use it To: Andrew Pinski Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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, 16 Aug 2021 06:22:32 -0000 On Sat, Aug 14, 2021 at 2:20 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > While working on some more boolean optimizations, I noticed > that there are places which does SSA_NAME@0 and then look > at then either use get_nonzero_bits or ssa_name_has_boolean_range > to see if the ssa name had a boolean range. This cleans this > up slightly by have a simple match pattern call gimple_truth_valued_p > which matches on SSA_NAME and checks ssa_name_has_boolean_range. > This is the first of the few cleanups I am going to do for > match and simplify and boolean related changes. > > gcc/ChangeLog: > > * match.pd: New match, gimple_truth_valued_p. > Use it for "{ 0 or 1 } * { 0 or 1 }", > "X / bool_range_Y", and "-(type)!A" simplifcations. > --- > gcc/match.pd | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 5cc6a9fd41c..b1f2aaaac02 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -98,6 +98,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (define_operator_list COND_TERNARY > IFN_COND_FMA IFN_COND_FMS IFN_COND_FNMA IFN_COND_FNMS) > > +/* Match for a SSA_NAME which has a range of [0,1] */ > +(match gimple_truth_valued_p > + SSA_NAME@0 > + (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@0)))) > + So we already have /* Try simple folding for X op !X, and X op X with the help of the truth_valued_p and logical_inverted_value predicates. */ (match truth_valued_p @0 (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1))) IMHO gimple_truth_valued_p is easily to be confused with this. I wonder whether you can simply add #if GIMPLE (match truth_valued_p SSA_NAME@0 (if (... #endif and use truth_valued_p? > /* With nop_convert? combine convert? and view_convert? in one pattern > plus conditionalize on tree_nop_conversion_p conversions. */ > (match (nop_convert @0) > @@ -230,11 +235,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 } */ > (simplify > - (mult SSA_NAME@1 SSA_NAME@2) > - (if (INTEGRAL_TYPE_P (type) > - && get_nonzero_bits (@1) == 1 > - && get_nonzero_bits (@2) == 1) > - (bit_and @1 @2))) > + (mult gimple_truth_valued_p@1 gimple_truth_valued_p@2) > + (bit_and @1 @2)) > > /* Transform x * { 0 or 1, 0 or 1, ... } into x & { 0 or -1, 0 or -1, ...}, > unless the target has native support for the former but not the latter. */ > @@ -347,9 +349,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (negate @0))) > /* X / bool_range_Y is X. */ > (simplify > - (div @0 SSA_NAME@1) > - (if (INTEGRAL_TYPE_P (type) && ssa_name_has_boolean_range (@1)) > - @0)) > + (div @0 gimple_truth_valued_p@1) > + @0) > /* X / X is one. */ > (simplify > (div @0 @0) > @@ -4207,12 +4208,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > /* -(type)!A -> (type)A - 1. */ > (simplify > - (negate (convert?:s (logical_inverted_value:s @0))) > + (negate (convert?:s (logical_inverted_value:s gimple_truth_valued_p@0))) > (if (INTEGRAL_TYPE_P (type) > && TREE_CODE (type) != BOOLEAN_TYPE > - && TYPE_PRECISION (type) > 1 > - && TREE_CODE (@0) == SSA_NAME > - && ssa_name_has_boolean_range (@0)) > + && TYPE_PRECISION (type) > 1) > (plus (convert:type @0) { build_all_ones_cst (type); }))) > > /* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0), since vector comparisons > -- > 2.27.0 >