From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 01C90383D83C for ; Mon, 16 Aug 2021 06:29:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01C90383D83C Received: by mail-ej1-x62c.google.com with SMTP id bt14so14008639ejb.3 for ; Sun, 15 Aug 2021 23:29:54 -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=63QJgcKMk4xXctYW9p8Xz6Hz1oQpe02IqWFgqmLA3SQ=; b=WMBeCqUhEHj3GTLhHuDnzNRNhQULleWhHXh/tEtzt09BSz0QewChlVf9/p1ybGB5qU 0/QctyyU7NVxXoXCJYpXzmYJi9slWR76OQyLESpngh2oujBttG0a+ChLk91USQo+lKyn E49YKI4FyBwN43abLmvG/U8ti10bXk3sPWxeVziXugWY4CsSN3X2lCfNjCFNCXcmaImv nvKxc9s2uFHD0osE3Z5FgF3sS6KYUEPSkDDuB/40VhRUGXaUr1oXpBYdQwfmE214Kc8A eSjq4PVWo4DafIs8yEH9CCD1Vut0EzW97J5SJmzVfRCyIKs1YU0Y/aI/o+acO5Ex4pTT knJQ== X-Gm-Message-State: AOAM531XlWRQSxJ9Tux6iuZIPpn5BEHBq1Y5AMLg/KhT0EF8TVdYiwnI 28eEsMveHDV1fcrpKi7sG2CoQN8gNcgGck/L2Cs= X-Google-Smtp-Source: ABdhPJwFrU5xijK3ZZR7rQ8iKqInfpHGadaMxF0sYJ1Re5ysVM7YTV1dX+RQojFP3rdvNvRnmcyBmTOjOwth7+3RNLU= X-Received: by 2002:a17:906:1901:: with SMTP id a1mr14810035eje.129.1629095394019; Sun, 15 Aug 2021 23:29:54 -0700 (PDT) MIME-Version: 1.0 References: <1628900361-27676-1-git-send-email-apinski@marvell.com> <1628900361-27676-2-git-send-email-apinski@marvell.com> In-Reply-To: <1628900361-27676-2-git-send-email-apinski@marvell.com> From: Richard Biener Date: Mon, 16 Aug 2021 08:29:43 +0200 Message-ID: Subject: Re: [PATCH 2/2] Fix 101805: Simplify min/max of boolean arguments To: Andrew Pinski Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.8 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:29:56 -0000 On Sat, Aug 14, 2021 at 2:21 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > I noticed this while Richard B. fixing PR101756. > Basically min of two bools is the same as doing an "and" > and max of two bools is doing an "ior". But that's only true for unsigned vals. For signed ones it would be the other way around and also restricted to 1-bit precision bools. For signed bools the gimple_truth_valued_p check likely is wrong as well unless 1-bit precision? IIRC Ada has non-1 bit precision BOOLEAN_TYPE nodes while fortran bools have 1-bit precision but different sizes. The vector bools are IIRC the only 'signed' bools we have and those have precisions != 1. I think we can use the fact that any non -1/0/1 value in a N-bit precision bool invokes undefined behavior though. But whether in a N-bit signed precision bool the canonical true value is -1 or 1 isn't as clear (maybe we can resort to TYPE_MIN/MAX_VALUE here, not sure). Way out would be to restrict all this to TYPE_UNSIGNED BOOLEAN_TYPE or non-BOOLEAN_TYPE? Richard. > gcc/ChangeLog: > > * match.pd: Add min/max patterns for bool types. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/bool-12.c: New test. > --- > gcc/match.pd | 10 +++++++++ > gcc/testsuite/gcc.dg/tree-ssa/bool-12.c | 27 +++++++++++++++++++++++++ > 2 files changed, 37 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-12.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index b1f2aaaac02..8fd60d08cfe 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3103,6 +3103,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > && (GIMPLE || !TREE_SIDE_EFFECTS (@1))) > (cond (cmp @2 @3) @1 @0)))) > > +/* max(bool0, bool1) -> bool0 | bool1 */ > +(simplify > + (max gimple_truth_valued_p@0 gimple_truth_valued_p@1) > + (bit_ior @0 @1)) > + > +/* min(bool0, bool1) -> bool0 & bool1 */ > +(simplify > + (min gimple_truth_valued_p@0 gimple_truth_valued_p@1) > + (bit_and @0 @1)) > + > /* Simplifications of shift and rotates. */ > > (for rotate (lrotate rrotate) > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-12.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-12.c > new file mode 100644 > index 00000000000..2d8ad9912d3 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-12.c > @@ -0,0 +1,27 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fdump-tree-optimized -fdump-tree-original" } */ > +#define bool _Bool > +int maxbool(bool ab, bool bb) > +{ > + int a = ab; > + int b = bb; > + int c; > + c = (a > b)?a : b; > + return c; > +} > +int minbool(bool ab, bool bb) > +{ > + int a = ab; > + int b = bb; > + int c; > + c = (a < b)?a : b; > + return c; > +} > +/* Original should have one of each MAX/MIN expressions. */ > +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "original" } */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "original"} } */ > + > +/* By the time we reach optimized, the MAX and MIN expressions > + should have been removed. */ > +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "optimized"} } */ > +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 0 "optimized"} } */ > -- > 2.27.0 >