From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sender4-pp-o91.zoho.com (sender4-pp-o91.zoho.com [136.143.188.91]) by sourceware.org (Postfix) with ESMTPS id B5471385800F; Thu, 13 May 2021 23:31:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B5471385800F ARC-Seal: i=1; a=rsa-sha256; t=1620948682; cv=none; d=zohomail.com; s=zohoarc; b=iSoN6akyvPMgKTVo7HVp6n1Ggk/eVbIQ894J2rCmq2X/b5UkpYKvR1FWgEDZD0DXdRwP6YkMeEUpeJReaplNwokHfyYC8X4xVgE/OhQlMjvNdb2EZALhquBdX0+TinLSgo18C+cX8iGFNhUZEftc2LRUTbr5HAQLEGLd2lABh/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620948682; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0WDW3tB+q/9a7kFgzdDXjGfrDE+Tsadkx8+YJyq8DuA=; b=NsYFwiNV5IqSrjtaDyziNq3rF+RrkfemZK6AVL0FU0fdGEII+H4kX4PRpvk3B2VNWtyOHRMYZTgKq4UdQCwLqwvEHwjl2rSUnXeX6N95gTTyiECvVsZHBwaQgIFM5ewfnvxLHTUyjkd3Yikp0CabAZ6aK10xMc8635zH7m8zlLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zoho.com; spf=pass smtp.mailfrom=bouanto@zoho.com; dmarc=pass header.from= header.from= Received: from [192.168.1.174] (38.87.11.6 [38.87.11.6]) by mx.zohomail.com with SMTPS id 1620948679891741.8191266895167; Thu, 13 May 2021 16:31:19 -0700 (PDT) Message-ID: Subject: Re: [PATCH] libgccjit: Handle truncation and extension for casts [PR 95498] From: Antoni Boucher To: David Malcolm Cc: Tom Tromey , jit@gcc.gnu.org, Antoni Boucher via Gcc-patches Date: Thu, 13 May 2021 19:31:17 -0400 In-Reply-To: <3ae55b5acc33b38c579ac9c293993c29adc55ae9.camel@redhat.com> References: <20200713003002.bs5hwv4gav6ml5rt@bouanto-laptop.localdomain> <874ki6txcc.fsf@tromey.com> <20210220221706.ewfq2b3i2mzx4ice@bouanto-desktop.localdomain> <3ae55b5acc33b38c579ac9c293993c29adc55ae9.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, 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: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 May 2021 23:31:40 -0000 Thanks for your answer. See my answers below: Le jeudi 13 mai 2021 =C3=A0 18:13 -0400, David Malcolm a =C3=A9crit=C2=A0: > On Sat, 2021-02-20 at 17:17 -0500, Antoni Boucher via Gcc-patches > wrote: > > Hi. > > Thanks for your feedback! > >=20 >=20 > Sorry about the delay in responding. >=20 > In the past I was hesitant about adding more cast support to libgccjit > since I felt that the user could always just create a union to do the > cast.=C2=A0 Then I tried actually using the libgccjit API to do this, and > realized how much work it adds, so I now think we do want to support > casting more types. >=20 >=20 > > See answers below: > >=20 > > On Sat, Feb 20, 2021 at 11:20:35AM -0700, Tom Tromey wrote: > > > > > > > > "Antoni" =3D=3D Antoni Boucher via Gcc-patches <=C2=A0=C2= =A0=20 > > > > > > > > gcc-patches@gcc.gnu.org> writes: > > >=20 > > > Antoni> gcc/jit/ > > > Antoni>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PR targe= t/95498 > > > Antoni>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* jit-pl= ayback.c: Add support to handle truncation > > > and extension > > > Antoni>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0in the c= onvert function. > > >=20 > > > Antoni> +=C2=A0 switch (dst_code) > > > Antoni> +=C2=A0=C2=A0=C2=A0 { > > > Antoni> +=C2=A0=C2=A0=C2=A0 case INTEGER_TYPE: > > > Antoni> +=C2=A0=C2=A0=C2=A0 case ENUMERAL_TYPE: > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 t_ret =3D convert_to_integer = (dst_type, expr); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto maybe_fold; > > > Antoni> + > > > Antoni> +=C2=A0=C2=A0=C2=A0 default: > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 gcc_assert (gcc::jit::active_= playback_ctxt); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 gcc::jit::active_playback_ctx= t->add_error (NULL, > > > "unhandled conversion"); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fprintf (stderr, "input expre= ssion:\n"); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 debug_tree (expr); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fprintf (stderr, "requested t= ype:\n"); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 debug_tree (dst_type); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return error_mark_node; > > > Antoni> + > > > Antoni> +=C2=A0=C2=A0=C2=A0 maybe_fold: > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (TREE_CODE (t_ret) !=3D C_= MAYBE_CONST_EXPR) >=20 > Do we even get C_MAYBE_CONST_EXPR in libgccjit?=C2=A0 That tree code is > defined in c-family/c-common.def; how can nodes of that kind be created > outside of the c-family? I am not sure, but that seems like it's only created in c-family indeed. However, we do use it in libgccjit here: https://github.com/gcc-mirror/gcc/blob/master/gcc/jit/jit-playback.c#L1180 >=20 > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0t_ret =3D fold (t_= ret); > > > Antoni> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return t_ret; > > >=20 > > > It seems weird to have a single 'goto' to maybe_fold, especially > > > inside > > > a switch like this. > > >=20 > > > If you think the maybe_fold code won't be reused, then it should > > > just > > > be > > > hoisted up and the 'goto' removed. > >=20 > > This actually depends on how the support for cast between integers > > and=20 > > pointers will be implemented (see below). > > If we will support truncating pointers (does that even make sense? > > and > > I=20 > > guess we cannot extend a pointer unless we add the support for=20 > > uint128_t), that label will be reused for that case. > > Otherwise, it might not be reused. > >=20 > > So, please tell me which option to choose and I'll update my patch. >=20 > FWIW I don't think we'll want to support truncating or extending > pointers. Ok, but do you think we'll want to support casts between integers and pointers? I opened an issue about this (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95438) and would be willing to do a patch for it eventually. > >=20 > > > On the other hand, if the maybe_fold code might be reused for some > > > other > > > case, then I suppose I would have the case end with 'break' and > > > then > > > have this code outside the switch. > > >=20 > > >=20 > > > In another message, you wrote: > > >=20 > > > Antoni> For your question, the current code already works with > > > boolean and > > > Antoni> reals and casts between integers and pointers is currently > > > not > > > Antoni> supported. > > >=20 > > > I am curious why this wasn't supported.=C2=A0 It seems like something > > > that > > > one might want to do. > >=20 > > I have no idea as this is my first contribution to gcc. > > But this would be indeed very useful and I opened an issue about > > this:=20 > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95438 > >=20 > > > thanks, > > > Tom > >=20 > > Thanks! > >=20 >=20 >=20