From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6F7773893C5C for ; Fri, 18 Jun 2021 20:54:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F7773893C5C Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-3XtTFXZ_PH2hoM4OnfMWlw-1; Fri, 18 Jun 2021 16:54:13 -0400 X-MC-Unique: 3XtTFXZ_PH2hoM4OnfMWlw-1 Received: by mail-qk1-f198.google.com with SMTP id 2-20020a3709020000b02903aa9873df32so6687516qkj.15 for ; Fri, 18 Jun 2021 13:54:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=kiJEzx+qLiLLVRyR8r1BxWvCCq6hMybu4G7FCuhydk8=; b=ifS3VfIvJDfQ3iSB4x76NKKvWkGleyFWOvWYDbdga0WDCnFo+cvlW3sIi61QF8m+h6 rL8Ku0hk1tUNQFVYbOwS5ALL0k912J1Vz2H6x2i4AAf7nXuTxgrlE6P4LGGEFBb6Xp23 DetIDvVsPeFiE5rOPMkQ2kjkdwaitiKo3G/yO/UXz/mYMbixnB+vkOkSbf1+O2jdYBCL xvNfEyOcXxKA/FOD5jJN40Y8HVlw1aI9rn6Wq2xz3uGIbW+PE9/sGSWnWioOEKUE38eY QVJOEmlD4Xl9T2tZuaXc+oGz3mX88YdrVktoB2dGw93PZ12N8csLtBefRWXym2YYfAYb e2rA== X-Gm-Message-State: AOAM530jzsWlGq2+PvEjzIYKWAvbHmzpX089e+wn+1CefKklkwl2kEgc DH7ZsXCy+3trgrqtymuZlWMYzu9p0qJV9LAK2ONVnNApnYCPbmjoFjYCWayPzkkKCcDesbbchAX Vy1NCOuw= X-Received: by 2002:a05:620a:22ec:: with SMTP id p12mr5109199qki.116.1624049653410; Fri, 18 Jun 2021 13:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4NHKUUEiG65Nuix5usPKAnkutQ6fo0cy0W9Ma1C/F/swmep9DlHGsqqFicWvsDnppLIq0Bg== X-Received: by 2002:a05:620a:22ec:: with SMTP id p12mr5109185qki.116.1624049653205; Fri, 18 Jun 2021 13:54:13 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.nh.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id z3sm4819475qkj.40.2021.06.18.13.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 13:54:12 -0700 (PDT) Message-ID: Subject: Re: [PATCH] libgccjit: Handle truncation and extension for casts [PR 95498] From: David Malcolm To: Antoni Boucher Cc: jit@gcc.gnu.org, Antoni Boucher via Gcc-patches Date: Fri, 18 Jun 2021 16:54:11 -0400 In-Reply-To: <4834aac911b9fc1f58d0e9cea8773775aad2a23e.camel@zoho.com> References: <20200713003002.bs5hwv4gav6ml5rt@bouanto-laptop.localdomain> <874ki6txcc.fsf@tromey.com> <20210220221706.ewfq2b3i2mzx4ice@bouanto-desktop.localdomain> <3ae55b5acc33b38c579ac9c293993c29adc55ae9.camel@redhat.com> <597ecec1c91c1176f740796e20432372377aa554.camel@redhat.com> <0f7f2bf386c29efa1403020cbb02bec815ce25fe.camel@zoho.com> <651ead30f4fa016c233c203bd5d3e749273ab92b.camel@redhat.com> <8d782bf220cc81c727f842b21d835b5b991d3a35.camel@zoho.com> <1f12388082367de4e8d2ea8fe802c22efd50c109.camel@redhat.com> <4834aac911b9fc1f58d0e9cea8773775aad2a23e.camel@zoho.com> User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: Fri, 18 Jun 2021 20:54:18 -0000 On Fri, 2021-06-18 at 16:42 -0400, Antoni Boucher wrote: > I'm sending the patch once again for review. > > As it's the first time I'll land a patch, I'm not sure what needs to be > done when it's approved. > Do I just commit it to the master branch directly? Commit (and push), yes, but... Please ensure the subject line of the commit matches our policy: "libgccjit: Handle truncation and extension for casts [PR95498]" is a good subject, whereas: "This patch handles truncation and extension for casts in jit." is not. We have some hooks that will only accept pushes if the commit message has a correctly formatted ChangeLog. The hooks ought to also add notification comments to bugzilla for any bugs mentioned in the commit message. See https://gcc.gnu.org/gitwrite.html#checkin FWIW in my own workflow I have a writable working copy that I keep for just doing pushes;  I do a git pull verify the build, then git am FOO.patch --ignore-date to apply the patch that was tested and approved, then do a last test with that, then git push That way I only push the patches that I've tested and have been approved, and the other ones are in an entirely separate working copy. This may be overkill though. I'm also on #gcc IRC right now on OFTC (dmalcolm) if you run into issues. Dave > > Thanks! > > Le vendredi 11 juin 2021 à 13:49 -0400, David Malcolm a écrit : > > On Thu, 2021-05-27 at 21:22 -0400, Antoni Boucher wrote: > > > Here's the patch with the condition removed. > > > I believe everything is now fixed. > > > Thanks! > > > > Thanks; this looks good to me.  Is this the latest version of the > > patch; would you like me to apply it? > > > > Dave > > > > > > > > Le jeudi 27 mai 2021 à 18:21 -0400, David Malcolm a écrit : > > > > On Tue, 2021-05-25 at 20:16 -0400, Antoni Boucher wrote: > > > > > I updated the patch according to the comments by Tom Tromey. > > > > > > > > > > There's one question left about your question regarding > > > > > C_MAYBE_CONST_EXPR, David: > > > > > > > > > > I am not sure if we can get a C_MAYBE_CONST_EXPR from > > > > > libgccjit, > > > > > and > > > > > it > > > > > indeed seems like it's only created in c-family. > > > > > However, we do use it in libgccjit here: > > > > > https://github.com/gcc-mirror/gcc/blob/master/gcc/jit/jit-playback.c#L1180 > > > > > > > > > > I tried removing the condition `if (TREE_CODE (t_ret) != > > > > > C_MAYBE_CONST_EXPR)` and all the tests of libgccjit still pass. > > > > > > > > > > That code was copied from here: > > > > > https://github.com/gcc-mirror/gcc/blob/master/gcc/c/c-convert.c#L175 > > > > > and might not be needed in libgccjit. > > > > > > > > > > Should I just remove the condition, then? > > > > > > > > I think so. > > > > > > > > Thanks > > > > Dave > > > > > > > > > > > > > > Le jeudi 13 mai 2021 à 19:58 -0400, David Malcolm a écrit : > > > > > > On Thu, 2021-05-13 at 19:31 -0400, Antoni Boucher wrote: > > > > > > > Thanks for your answer. > > > > > > > > > > > > > > See my answers below: > > > > > > > > > > > > > > Le jeudi 13 mai 2021 à 18:13 -0400, David Malcolm a écrit : > > > > > > > > On Sat, 2021-02-20 at 17:17 -0500, Antoni Boucher via > > > > > > > > Gcc- > > > > > > > > patches > > > > > > > > wrote: > > > > > > > > > Hi. > > > > > > > > > Thanks for your feedback! > > > > > > > > > > > > > > > > > > > > > > > > > Sorry about the delay in responding. > > > > > > > > > > > > > > > > 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.  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. > > > > > > > > > > > > > > > > > > > > > > > > > See answers below: > > > > > > > > > > > > > > > > > > On Sat, Feb 20, 2021 at 11:20:35AM -0700, Tom Tromey > > > > > > > > > wrote: > > > > > > > > > > > > > > > "Antoni" == Antoni Boucher via Gcc-patches > > > > > > > > > > > > > > > <   > > > > > > > > > > > > > > > gcc-patches@gcc.gnu.org> writes: > > > > > > > > > > > > > > > > > > > > Antoni> gcc/jit/ > > > > > > > > > > Antoni>         PR target/95498 > > > > > > > > > > Antoni>         * jit-playback.c: Add support to > > > > > > > > > > handle > > > > > > > > > > truncation > > > > > > > > > > and extension > > > > > > > > > > Antoni>         in the convert function. > > > > > > > > > > > > > > > > > > > > Antoni> +  switch (dst_code) > > > > > > > > > > Antoni> +    { > > > > > > > > > > Antoni> +    case INTEGER_TYPE: > > > > > > > > > > Antoni> +    case ENUMERAL_TYPE: > > > > > > > > > > Antoni> +      t_ret = convert_to_integer (dst_type, > > > > > > > > > > expr); > > > > > > > > > > Antoni> +      goto maybe_fold; > > > > > > > > > > Antoni> + > > > > > > > > > > Antoni> +    default: > > > > > > > > > > Antoni> +      gcc_assert > > > > > > > > > > (gcc::jit::active_playback_ctxt); > > > > > > > > > > Antoni> +      gcc::jit::active_playback_ctxt- > > > > > > > > > > > add_error > > > > > > > > > > (NULL, > > > > > > > > > > "unhandled conversion"); > > > > > > > > > > Antoni> +      fprintf (stderr, "input > > > > > > > > > > expression:\n"); > > > > > > > > > > Antoni> +      debug_tree (expr); > > > > > > > > > > Antoni> +      fprintf (stderr, "requested type:\n"); > > > > > > > > > > Antoni> +      debug_tree (dst_type); > > > > > > > > > > Antoni> +      return error_mark_node; > > > > > > > > > > Antoni> + > > > > > > > > > > Antoni> +    maybe_fold: > > > > > > > > > > Antoni> +      if (TREE_CODE (t_ret) != > > > > > > > > > > C_MAYBE_CONST_EXPR) > > > > > > > > > > > > > > > > Do we even get C_MAYBE_CONST_EXPR in libgccjit?  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 > > > > > > > > > > > > > > > > > > > > > > > > > Antoni> +       t_ret = fold (t_ret); > > > > > > > > > > Antoni> +      return t_ret; > > > > > > > > > > > > > > > > > > > > It seems weird to have a single 'goto' to maybe_fold, > > > > > > > > > > especially > > > > > > > > > > inside > > > > > > > > > > a switch like this. > > > > > > > > > > > > > > > > > > > > If you think the maybe_fold code won't be reused, > > > > > > > > > > then > > > > > > > > > > it > > > > > > > > > > should > > > > > > > > > > just > > > > > > > > > > be > > > > > > > > > > hoisted up and the 'goto' removed. > > > > > > > > > > > > > > > > > > This actually depends on how the support for cast > > > > > > > > > between > > > > > > > > > integers > > > > > > > > > and > > > > > > > > > pointers will be implemented (see below). > > > > > > > > > If we will support truncating pointers (does that even > > > > > > > > > make > > > > > > > > > sense? > > > > > > > > > and > > > > > > > > > I > > > > > > > > > guess we cannot extend a pointer unless we add the > > > > > > > > > support > > > > > > > > > for > > > > > > > > > uint128_t), that label will be reused for that case. > > > > > > > > > Otherwise, it might not be reused. > > > > > > > > > > > > > > > > > > So, please tell me which option to choose and I'll > > > > > > > > > update > > > > > > > > > my > > > > > > > > > patch. > > > > > > > > > > > > > > > > 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? > > > > > > > > > > > > Yes, though we probably want to reject truncating a pointer > > > > > > into > > > > > > a > > > > > > smaller integer type. > > > > > > > > > > > > > I opened an issue about this > > > > > > > (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95438) and > > > > > > > would > > > > > > > be > > > > > > > willing to do a patch for it eventually. > > > > > > > > > > > > > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > In another message, you wrote: > > > > > > > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > > > > > > > I am curious why this wasn't supported.  It seems > > > > > > > > > > like > > > > > > > > > > something > > > > > > > > > > that > > > > > > > > > > one might want to do. > > > > > > > > > > > > > > > > > > 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: > > > > > > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95438 > > > > > > > > > > > > > > > > > > > thanks, > > > > > > > > > > Tom > > > > > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >