From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id A06F13857714 for ; Tue, 4 Jul 2023 08:58:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A06F13857714 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fafe87c6fbso8267546e87.3 for ; Tue, 04 Jul 2023 01:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688461127; x=1691053127; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ciWpn8qoPOy8xWGfpOKHDabEtjzbFuf5hzKe7oa+Zbs=; b=XgT5TYkrm5IM5h43j6yJ9ETBXiksyRTMpQkUDQNkuF3Qh6lF9NNoKWRjVdtHm4pe23 HQF4rUhvAgSZYvo6qhJGzYULXOD06iT8w1DJfoJFeq91gHRo/+rsFbYMEC6u9TVupX2U 6uqsLeacui/mbj07RzH+Hj6KJ9U1WGOwrGTJFAIG5G7pYqCjU+pREu0K5Rq/Vhun3BJq Qz18iR34SfvUa+15QKNhbzFoSbMLGlkb/Oe4y2VosPbSiWETLsEoS+MOrX5uINh/j5mX 1CDyuoTEOi7+AwpxCbG4fZZsR8JlgVbIoPwkvmQoCGLxTeQSJJL+PLMdlrHWR0gePcvu L7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688461127; x=1691053127; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ciWpn8qoPOy8xWGfpOKHDabEtjzbFuf5hzKe7oa+Zbs=; b=AweJcN+i4oEzHLPQVmvUDsM7EGCxfuWdsu/sER+PPWPC1eDkfz+NLyk+nx4Y3JuPA9 VN3EtLrU4JQmDDY2YbdA72iG16B05YfT1hHuIaXPffDDZcvSYy44BDQ/8XJ8+TOROgRT fRColtn6z6uszJY4xHpRbMRPuUArsoMGui2gBeQJOUf7KSzbFWyUe6ijxvnDLzu88HIF W7c+K4rtkLYqO0jzMZyw6hrIxgoDzVsSY0fLPfUrfrJi4yeLYVtutbwi6a/cjHxEvjN/ SyiWRw5r0W4G3v2qmoAnWN7dPOBmNwyw8YNRywjA0ZuutCFzrDo8cKNPweW5XP1ATjKI lDsw== X-Gm-Message-State: ABy/qLZQg9faV0n08l/ALZNOBAybpmlei+hnms6aTvl0x4gDSpHZ9v8r vKjypNQcBTJTsGXgeqpoUMXIYSAViAgY4e4xNcC2kfIj X-Google-Smtp-Source: APBJJlGMhf1lWAiaz5TlCVmBcHNt/YXH1zUpQ0oLVMa6AfcIW1y/wAoapuxRxDLMyF0oBQIU6r19EFSoFhkZjLhKPtQ= X-Received: by 2002:a2e:9856:0:b0:2b6:ce35:2e9e with SMTP id e22-20020a2e9856000000b002b6ce352e9emr7971808ljj.44.1688461126886; Tue, 04 Jul 2023 01:58:46 -0700 (PDT) MIME-Version: 1.0 References: <20230701082216.299104-1-apinski@marvell.com> <20230701082216.299104-2-apinski@marvell.com> In-Reply-To: <20230701082216.299104-2-apinski@marvell.com> From: Richard Biener Date: Tue, 4 Jul 2023 10:55:25 +0200 Message-ID: Subject: Re: [PATCH 2/2] PR 110487: `(a !=/== CST1 ? CST2 : CST3)` pattern for type safety To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,PLING_QUERY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sat, Jul 1, 2023 at 10:23=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > The problem here is we might produce some values out of the type's > min/max (and/or valid values, e.g. signed booleans). The fix is to > use an integer type which has the same precision and signedness > as the original type. > > Note two_value_replacement in phiopt had the same issue in previous > versions; though I don't know if a problem will show up there. > > OK? Bootstrapped and tested on x86_64-linux-gnu. OK. > gcc/ChangeLog: > > PR tree-optimization/110487 > * match.pd (a !=3D/=3D=3D CST1 ? CST2 : CST3): Always > build a nonstandard integer and use that. > --- > gcc/match.pd | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/gcc/match.pd b/gcc/match.pd > index a0d114f6a16..9748ad8466e 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -4797,24 +4797,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > tree type1; > if ((eqne =3D=3D EQ_EXPR) ^ (wi::to_wide (@1) =3D=3D min)) > std::swap (arg0, arg1); > - if (TYPE_PRECISION (TREE_TYPE (@0)) =3D=3D TYPE_PRECISION (type)) > - { > - /* Avoid performing the arithmetics in bool type which has dif= ferent > - semantics, otherwise prefer unsigned types from the two wit= h > - the same precision. */ > - if (TREE_CODE (TREE_TYPE (arg0)) =3D=3D BOOLEAN_TYPE > - || !TYPE_UNSIGNED (type)) > - type1 =3D TREE_TYPE (@0); > - else > - type1 =3D TREE_TYPE (arg0); > - } > - else if (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type)) > + if (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type)) > type1 =3D TREE_TYPE (@0); > else > type1 =3D type; > - min =3D wide_int::from (min, TYPE_PRECISION (type1), > + auto prec =3D TYPE_PRECISION (type1); > + auto unsign =3D TYPE_UNSIGNED (type1); > + type1 =3D build_nonstandard_integer_type (prec, unsign); > + min =3D wide_int::from (min, prec, > TYPE_SIGN (TREE_TYPE (@0))); > - wide_int a =3D wide_int::from (wi::to_wide (arg0), TYPE_PRECISION= (type1), > + wide_int a =3D wide_int::from (wi::to_wide (arg0), prec, > TYPE_SIGN (type)); > enum tree_code code; > wi::overflow_type ovf; > @@ -4822,7 +4814,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > { > code =3D PLUS_EXPR; > a -=3D min; > - if (!TYPE_UNSIGNED (type1)) > + if (!unsign) > { > /* lhs is known to be in range [min, min+1] and we want to= add a > to it. Check if that operation can overflow for those = 2 values > @@ -4836,7 +4828,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > { > code =3D MINUS_EXPR; > a +=3D min; > - if (!TYPE_UNSIGNED (type1)) > + if (!unsign) > { > /* lhs is known to be in range [min, min+1] and we want to= subtract > it from a. Check if that operation can overflow for th= ose 2 > -- > 2.31.1 >