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 ESMTPS id 883843857735 for ; Thu, 23 Nov 2023 10:56:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 883843857735 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 883843857735 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700737004; cv=none; b=pXf8psEAzk2qJeZMpSEHzmhn9pJcQUK8lp0mr7cuTnVGfNHa9qoMJ0sPkKxdjeXnnIyAjghXAVoeoa8ew6Yzeze8txXko4oHDHAxDqw3PFnAGY+nNM0+C4s+tWQG1e2qsQUKyvHNvzDKdGiemUH5ehobm6UF2drEAbrFmpK+PnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700737004; c=relaxed/simple; bh=2WPUQJJoG3TP/9NTyV4D9yK072ly/gODiAEiJ3a7KHY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=JMj19GbIkeyxUisB0mWMOkdcflQfgKa/yj74SvXfnDvDfwHcDp1KB+N+10f1PMqLWZp7tv52e5fkcQt/l+oZLXzOJ9N/8AWUQyYBEDcPw0ra0/SXSo+KnQG+cXDXabps0COMSO6zPDTvV6gXlRmyyzlkKj4KAVEn0gj0hUnPjSc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700737002; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=5sjOf/qbYasfqaZtXZKKQgvCpcyp9FZnm9LzU4Kxa0A=; b=Cbd+2P+AUk59F3SoRRWEt7lgVaLKhf736dnLuZsGPO1vLR18Namx0kKu7VxyasTjWO25bd DD7pO0XGshLVUPz884jGMMXinOPvzjFsJbkITA8D+fZKQV6IvYhHQulohZlWoK+ZCLVxA9 bzm7lwVJftJ4/zblPStSthGSYivKBlk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-35ZTWcnvMvSSLQ8Kz_V4Dg-1; Thu, 23 Nov 2023 05:56:38 -0500 X-MC-Unique: 35ZTWcnvMvSSLQ8Kz_V4Dg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1952A101A529; Thu, 23 Nov 2023 10:56:38 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0A671C060B0; Thu, 23 Nov 2023 10:56:37 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3ANAuZMS888973 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Nov 2023 11:56:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3ANAuYWR888972; Thu, 23 Nov 2023 11:56:34 +0100 Date: Thu, 23 Nov 2023 11:56:33 +0100 From: Jakub Jelinek To: Richard Biener Cc: Richard Biener , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] lower-bitint: Fix up -fnon-call-exceptions bit-field load lowering [PR112668] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 Thu, Nov 23, 2023 at 11:01:08AM +0100, Richard Biener wrote: > > --- gcc/gimple-lower-bitint.cc.jj 2023-11-14 10:52:16.000000000 +0100 > > +++ gcc/gimple-lower-bitint.cc 2023-11-22 14:34:17.327140002 +0100 > > @@ -1687,7 +1687,22 @@ bitint_large_huge::handle_load (gimple * > > edge e = split_block (gsi_bb (m_gsi), g); > > make_edge (e->src, eh_edge->dest, EDGE_EH)->probability > > = profile_probability::very_unlikely (); > > - m_init_gsi.bb = e->dest; > > + m_init_gsi = gsi_last_bb (e->dest); > > shouldn't that be gsi_start_bb (e->dest) if we want to continue inserting > before the "old" stmt? > > > + if (!gsi_end_p (m_init_gsi)) > > + gsi_next (&m_init_gsi); > > That would always put it at the end? > > > + if (gsi_bb (save_gsi) == e->src) > > + { > > + if (gsi_end_p (save_gsi)) > > + { > > + save_gsi = gsi_last_bb (e->dest); > > + if (!gsi_end_p (save_gsi)) > > + gsi_next (&save_gsi); > > + } > > + else > > + save_gsi = gsi_for_stmt (gsi_stmt (save_gsi)); > > uhm. It might be better to instead of doing save_gsi = m_gsi > save gsi_stmt () and gsi_bb () to avoid accessing the now > possibly invalid iterator? > > If there were only one iterator I'd say we want a > > split_block_{after,before} (&gsi); > > which hides the detail of updating the iterator. But you have the > additional issue of possibly updating another iterator where as said > the better solution would be to reconstruct it from a gimple * > (or basic_block if at end). Maybe we can have a > gsi_update_after_spli_block (&gsi, basic_block-that-was-split)? > > If you think any of this would be an improvement (but also see > the gsi_last_bb vs gsi_start issue) feel free to improve. > > Otherwise OK as-is. The code has 2 iterators and pretty much everything in the pass inserts statements before iterator. m_gsi is the iterator before which everything is inserted, initially initialized to m_gsi = gsi_for_stmt (stmt); where stmt is the statement we are lowering, but updated in many places when splitting a bb etc. So, it needs to behave right for the insert before behavior, gsi_end_p means insert at the end of bb. Then m_init_gsi is initially one statement earlier, so insert code after that statement instead: m_init_gsi = m_gsi; gsi_prev (&m_init_gsi); with gsi_end_p meaning insert at the start of bb. Because all the pass infrastructure is for inserting before rather than after, when inserting (temporarily) after m_init_gsi, it does gimple_stmt_iterator save_gsi = m_gsi; m_gsi = m_init_gsi; if (gsi_end_p (m_gsi)) m_gsi = gsi_after_labels (gsi_bb (m_gsi)); else gsi_next (&m_gsi); and then it can insert before m_gsi and finally when done there m_gsi = save_gsi; The problematic splitting of the bb is during this temporary override to insert stuff after m_init_gsi. For the save_gsi update, I believe I'm reconstructing it from the stmt if any and set to gsi_end_p if it was gsi_end_p before: + if (gsi_end_p (save_gsi)) + { + save_gsi = gsi_last_bb (e->dest); + if (!gsi_end_p (save_gsi)) + gsi_next (&save_gsi); + } + else + save_gsi = gsi_for_stmt (gsi_stmt (save_gsi)); I don't know how else to re-create a gsi_end_p iterator from a bb (other option I know of would be gsi_start_bb and gsi_prev if !gsi_end_p, but stmt after gsi_last_bb seems to match more the intent). Now, regarding m_init_gsi, I think I'll need to play around, maybe I should have in the end insert after and update behavior rather than insert after, and that could be achieved by adding m_init_gsi = m_gsi; gsi_prev (&m_init_gsi); before the m_gsi = save_gsi; restore in all the 3 places and then no other updates of m_init_gsi would be needed. Except gsi_prev likely won't like the gsi_end_p (m_gsi) case, so maybe m_init_gsi = m_gsi; if (gsi_end_p (m_init_gsi)) m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi)); else gsi_prev (&m_init_gsi); m_gsi = save_gsi; Jakub