From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id C90493858D28 for ; Mon, 24 Apr 2023 12:37:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C90493858D28 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-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2a8b62cfaceso41122771fa.2 for ; Mon, 24 Apr 2023 05:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339839; x=1684931839; 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=OtA+uRARSJCz74rqmBJV4AdeEDKWK1WrgZpMeXBHhps=; b=BSAsTKL7naYjHnHh96RulDQT6jk4GzGLYb+YFmQkUFOUm0+1GYdbuFEA845NqBq439 o6/FqivPZZMDlmacbv9PA3Q4770xvv4vueFzP84qT+zThFN1GNvXD7yRp1hYK8bdvY4P 7v/5FpDcWWKja2OriaeZLLUNt4ujt01QuZazB7TYj8f3fjQhxO+3GVaLrf3+CDUj9pc4 vKdjZ4nxNTTulwMxtNI1SrWYav1OwTui6pCbyVvAPoQJy1cuneCQRIEbkBvrXol3CdLa uBzMu6OpZn7izvZFo9rFeaSrTsKpjW5nQxH9tZm+8UYpem4NIiI0Wu0ZEqPb83daROvG vurA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339839; x=1684931839; 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=OtA+uRARSJCz74rqmBJV4AdeEDKWK1WrgZpMeXBHhps=; b=EZDGdUwwp95zF/QqQ8lvoFBTUDypixmKmQMqFEWorGBX33iCKK8WDW//+4jKrwGt37 0sWONIQ1arqIbZO3eP/tKhk25fjC8qK/dVewyQr6uGxLhDgzbNDuXqh1a6sZJ7SiPdNt /PwF3W/9i9FG+9kTqdtSb559bHy+RhEUmP7oF2/AihUdKKCwRjI9FgOU7+5/Dc2sGhgh TtJVt/BV1d120knLjM8JLLktprlZnP6QnLCt8i93NzwBqPbnXh5+wB8Y4OpMMjJd/yNT 4WgFZcgAkfFos1LobtCA0qXIkp/HyxYPwJJE+A7tls2KB6eOLake2co2YClegIbwBN4Y cZMA== X-Gm-Message-State: AAQBX9f4xWzWqFtDf4aC2oHjiyDfjuOIR5R0Qju/Ijcz/lFMmQkm79G6 V61c9a6k9ygHxIGLKZ/dbbgOjb8heNYHXaaiwJ8= X-Google-Smtp-Source: AKy350a9x6jBPHvBjgga0Xq528EmYtyPFgD6hKKMDAlBvTcq9orqE/fh+ogemc/twqQXsn46LTLykyrR8FgtL8mg1mg= X-Received: by 2002:a2e:7d05:0:b0:293:4ff0:678a with SMTP id y5-20020a2e7d05000000b002934ff0678amr2352361ljc.22.1682339839276; Mon, 24 Apr 2023 05:37:19 -0700 (PDT) MIME-Version: 1.0 References: <20230424074332.141890-1-aldyh@redhat.com> <9db305b9-62fb-1b07-656a-13d029a7f730@redhat.com> In-Reply-To: From: Richard Biener Date: Mon, 24 Apr 2023 14:35:53 +0200 Message-ID: Subject: Re: [PATCH] Pass correct type to irange::contains_p() in ipa-cp.cc. To: Aldy Hernandez Cc: GCC patches , Andrew MacLeod Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.6 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,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 Mon, Apr 24, 2023 at 2:32=E2=80=AFPM Aldy Hernandez w= rote: > > > > On 4/24/23 14:10, Richard Biener wrote: > > On Mon, Apr 24, 2023 at 1:51=E2=80=AFPM Aldy Hernandez wrote: > >> > >> > >> > >> On 4/24/23 10:30, Richard Biener wrote: > >>> On Mon, Apr 24, 2023 at 9:44=E2=80=AFAM Aldy Hernandez via Gcc-patche= s > >>> wrote: > >>>> > >>>> There is a call to contains_p() in ipa-cp.cc which passes incompatib= le > >>>> types. This currently works because deep in the call chain, the leg= acy > >>>> code uses tree_int_cst_lt which performs the operation with > >>>> widest_int. With the upcoming removal of legacy, contains_p() will = be > >>>> stricter. > >>>> > >>>> OK pending tests? > >>>> > >>>> gcc/ChangeLog: > >>>> > >>>> * ipa-cp.cc (ipa_range_contains_p): New. > >>>> (decide_whether_version_node): Use it. > >>>> --- > >>>> gcc/ipa-cp.cc | 16 +++++++++++++++- > >>>> 1 file changed, 15 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc > >>>> index b3e0f62e400..c8013563796 100644 > >>>> --- a/gcc/ipa-cp.cc > >>>> +++ b/gcc/ipa-cp.cc > >>>> @@ -6180,6 +6180,19 @@ decide_about_value (struct cgraph_node *node,= int index, HOST_WIDE_INT offset, > >>>> return true; > >>>> } > >>>> > >>>> +/* Like irange::contains_p(), but convert VAL to the range of R if > >>>> + necessary. */ > >>>> + > >>>> +static inline bool > >>>> +ipa_range_contains_p (const irange &r, tree val) > >>>> +{ > >>>> + if (r.undefined_p ()) > >>>> + return false; > >>>> + > >>>> + val =3D fold_convert (r.type (), val); > >>> > >>> I think that's wrong, it might truncate 'val'. I think we'd want > >>> > >>> if (r.undefined_p () || !int_fits_type_p (val, r.type ())) > >>> return false; > >> > >> This won't work for pointers. Is there a suitable version that handle= s > >> pointers as well? > > > > Where does it not work? And when do you get pointer values/types > > where they mismatch sufficiently (how?) to make ranger unhappy? > > > > It's not ranger that's unhappy, this is just irange::contains_p(). > > IPA works on both integers and pointers, and pointers don't have > TYPE_MIN/MAX_VALUE defined, so we ICE in int_fits_type_p: > > type_low_bound =3D TYPE_MIN_VALUE (type); > type_high_bound =3D TYPE_MAX_VALUE (type); Ah. The code handles NULL TYPE_MIN/MAX_VALUE just fine so I wonder if it works to change the above to type_low_bound =3D INTEGRAL_TYPE_P (type) ? TYPE_MIN_VALUE (type) : NULL= _TREE; ... alternatively you could use wi::fits_to_tree_p (wi::to_wide (val), type) from the IPA code. Richard.