From patchwork Thu Mar 14 08:10:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 87172 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8023385841E for ; Thu, 14 Mar 2024 08:11:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 444423858C39 for ; Thu, 14 Mar 2024 08:10:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 444423858C39 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 444423858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710403850; cv=none; b=ETkAFcJ5n2hB3p22macoYjFAEDZlnTG6OCE2vQzt4dYLnG5TMcwKqrOnnylYsc54dTiMIURurcK3vXOwjHnCbPk4pZ6QLO8HMSFNCxkllCBUFcJk1UFKYoTlMSOlZ319/sQ4wspRnF0Q1/DC1Okf/HPrO3yz7bkOAGYhsW+eAe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710403850; c=relaxed/simple; bh=VynPCQL9CLq0WUqreCZkuwfvIGrsCHMOWnUvAnKjsPs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=RKjUDGyp7AT2xk1XBRtrevrXaNIhhnkb+F5yf++IRvsROj99Lk4mYP/jiGQmnSoB5pydNYUJxRBIJdx/nh2rt34hpTSBsx8C1RFRay5o519YIcfCQaoyBJYjmWAxX5nun5uCXQj7EKF+E76tpmAXDcsY86U7iiAQNnBlP+Yhjoo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710403847; 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; bh=KjJRTD6cmb7gkOepEMLZmF1pUh+m9EfU0Glgwe+RSY4=; b=GajnrVF8cjkInRB+g5oi/M97x4r50tvALikbLej5R5OXwGCh+WNVCaD6aDXxd1JOqJiyOB g8PDhIEpc1Lq3JX7UKw7DsN/SHDwXpAwwKfNAAd85vMpfB4l3sdYBzYzpaA66lPwwovTg8 /UdKBwZqbX5BheB/0i3Ypp4eKjDoXV4= 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-55-tHsucjTWMemKOnGcdQN5YQ-1; Thu, 14 Mar 2024 04:10:46 -0400 X-MC-Unique: tHsucjTWMemKOnGcdQN5YQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 D293A800264; Thu, 14 Mar 2024 08:10:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 984601121306; Thu, 14 Mar 2024 08:10:45 +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 42E8Ah7R3677480 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 14 Mar 2024 09:10:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42E8Ah1H3677479; Thu, 14 Mar 2024 09:10:43 +0100 Date: Thu, 14 Mar 2024 09:10:43 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-iterator: Some gsi_safe_insert_*before fixes Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! When trying to use the gsi_safe_insert*before APIs in bitint lowering, I've discovered 3 issues and the following patch addresses those: 1) both split_block and split_edge update CDI_DOMINATORS if they are available, but because edge_before_returns_twice_call first splits and then adds an extra EDGE_ABNORMAL edge and then removes another one, the immediate dominators of both the new bb and the bb with returns_twice call need to change 2) the new EDGE_ABNORMAL edge had uninitialized probability; this patch copies the probability from the edge that is going to be removed and similarly copies other flags (EDGE_EXECUTABLE, EDGE_DFS_BACK, EDGE_IRREDUCIBLE_LOOP etc.) 3) if edge_before_returns_twice_call splits a block, then the bb with returns_twice call changes, so the gimple_stmt_iterator for it is no longer accurate, it points to the right statement, but gsi_bb and gsi_seq are no longer correct; the patch updates it Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-14 Jakub Jelinek * gimple-iterator.cc (edge_before_returns_twice_call): Copy all flags and probability from ad_edge to e edge. If CDI_DOMINATORS are computed, recompute immediate dominator of other_edge->src and other_edge->dest. (gsi_safe_insert_before, gsi_safe_insert_seq_before): Update *iter for the returns_twice call case to the gsi_for_stmt (stmt) to deal with update it for bb splitting. Jakub --- gcc/gimple-iterator.cc.jj 2024-03-13 13:03:08.073117732 +0100 +++ gcc/gimple-iterator.cc 2024-03-13 15:16:45.294317700 +0100 @@ -997,7 +997,18 @@ edge_before_returns_twice_call (basic_bl add_phi_arg (new_phi, gimple_phi_arg_def_from_edge (phi, ad_edge), e, gimple_phi_arg_location_from_edge (phi, ad_edge)); } + e->flags = ad_edge->flags; + e->probability = ad_edge->probability; remove_edge (ad_edge); + if (dom_info_available_p (CDI_DOMINATORS)) + { + set_immediate_dominator (CDI_DOMINATORS, other_edge->src, + recompute_dominator (CDI_DOMINATORS, + other_edge->src)); + set_immediate_dominator (CDI_DOMINATORS, other_edge->dest, + recompute_dominator (CDI_DOMINATORS, + other_edge->dest)); + } } return other_edge; } @@ -1045,6 +1056,7 @@ gsi_safe_insert_before (gimple_stmt_iter if (new_bb) e = single_succ_edge (new_bb); adjust_before_returns_twice_call (e, g); + *iter = gsi_for_stmt (stmt); } else gsi_insert_before (iter, g, GSI_SAME_STMT); @@ -1075,6 +1087,7 @@ gsi_safe_insert_seq_before (gimple_stmt_ if (g == l) break; } + *iter = gsi_for_stmt (stmt); } else gsi_insert_seq_before (iter, seq, GSI_SAME_STMT);