From patchwork Tue Sep 15 08:36:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1364163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=ZRoEP3rM; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BrGnL0SDlz9sR4 for ; Tue, 15 Sep 2020 18:37:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FF56386F46C; Tue, 15 Sep 2020 08:37:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id CC95D3857801 for ; Tue, 15 Sep 2020 08:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC95D3857801 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x330.google.com with SMTP id b79so2528694wmb.4 for ; Tue, 15 Sep 2020 01:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=xigZXmOVAuADPr4qR0tJTK1Kv9rJFQpMBqhEDQP/v0g=; b=ZRoEP3rMLW22vcaZ4c6PgNC4+FgNoP9ISygHyDvO1Fjq+B9EdB/Yan4rASZow/nonS ihOrcTm6CZdPCz+1H5u8K8BO2sOF3n73ibqdXXeNO27NdKyQkc9mwwlJSiPWaraeqW0U j5uEC3Hh4tO1ZhgBi8SphkyzkejTGfyYA3BzCf7rE6uO3Cvw5v5Sv8oBNcIMs8WTFNy7 lMKd+wA9F8zP6Voz3s8d5RQs6XxD192kXnMPsyNeIMZ8HnMPTDd7FZocyvMoQ8oz9djF rms5v63mBrTrbnVv3X+WaPxnZFcG3PZq8s9nJGg71p+5BKXdcp1CxpKS4OUk4EEOwwnW ZY5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=xigZXmOVAuADPr4qR0tJTK1Kv9rJFQpMBqhEDQP/v0g=; b=irZ2Lh5a0ZCoM2bireCOsQp3QXKvorI/Ayb746N37i3lYJ5ODjSmAAYX5lFU6ZVSJQ M9mT+98UJLnEVieBaV9MKRQi0EMKpnBNhepPCKcrOV8GS8nYOLwtcBEzLxjM7s5X84hx 7RYm2PWEkMU2HVFwcyOVPEy1HeE8NyskoClUH7a5uKai0J7AkBbms8OuL3pCGwfImjSM A/fNOzDZMbNnYwU/HTnBo1s0dRqRQug2rXigKAseq+gMQKIHFPlK2A4L7uzC+O9YmNDl 3TgfA7NgmhgnfbEFs4JAjAnKuRAOQv3Wnzy1n9Sgrg0cxHW1ZuHztDJJ/9b3c/kgURvR rAhw== X-Gm-Message-State: AOAM533NVOgZWxU8/oCOHNVmJnUM940G1XaihUqeNlioxkCp0pManiJQ dZptG17xCEakeXLZrFHlgRFs6GWk795iWqOC X-Google-Smtp-Source: ABdhPJzrecg6BNXNflkslYlE30dkK3knojrgwZaoM/rmJ3S/o9iDWleh1lgmUx8P1yrg4bcivIfcwA== X-Received: by 2002:a1c:e1d6:: with SMTP id y205mr3486016wmg.92.1600159036468; Tue, 15 Sep 2020 01:37:16 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:9230:7f82:53f4:769e:54b6]) by smtp.gmail.com with ESMTPSA id t4sm25565081wrr.26.2020.09.15.01.37.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Sep 2020 01:37:15 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix pessimization in EH cleanup pass Date: Tue, 15 Sep 2020 10:36:20 +0200 Message-ID: <6993380.JPCJVM3AQ6@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, the cleanup_all_empty_eh function was originally doing a post-order traversal of the EH region tree to optimize it: /* Do a post-order traversal of the EH region tree. Examine each post_landing_pad block and see if we can eliminate it as empty. */ That's sensible since the worker function cleanup_empty_eh punts if the number of outgoing edges from landing pads is not 0 or 1: /* There can be zero or one edges out of BB. This is the quickest test. */ switch (EDGE_COUNT (bb->succs)) { case 0: e_out = NULL; break; case 1: e_out = single_succ_edge (bb); break; default: return false; } This was recently changed to use another order and this trivially breaks testcases with nested regions like the attached one. So the attached patch restores the post-order traversal and it also contains a small tweak to the line debug info to avoid a problematic inheritance for coverage measurement. Tested on x86_64-suse-linux, OK for the mainline? 2020-09-15 Eric Botcazou Pierre-Marie Derodat * tree-eh.c (lower_try_finally_dup_block): Backward propagate slocs to stack restore builtin calls. (cleanup_all_empty_eh): Do again a post-order traversal of the EH region tree. 2020-09-15 Eric Botcazou * gnat.dg/concat4.adb: New test. diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 4246dca8806..ed32f80220d 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -899,23 +899,26 @@ lower_try_finally_dup_block (gimple_seq seq, struct leh_state *outer_state, gtry *region = NULL; gimple_seq new_seq; gimple_stmt_iterator gsi; + location_t last_loc = UNKNOWN_LOCATION; new_seq = copy_gimple_seq_and_replace_locals (seq); - for (gsi = gsi_start (new_seq); !gsi_end_p (gsi); gsi_next (&gsi)) + for (gsi = gsi_last (new_seq); !gsi_end_p (gsi); gsi_prev (&gsi)) { gimple *stmt = gsi_stmt (gsi); /* We duplicate __builtin_stack_restore at -O0 in the hope of eliminating - it on the EH paths. When it is not eliminated, make it transparent in - the debug info. */ + it on the EH paths. When it is not eliminated, give it the next + location in the sequence or make it transparent in the debug info. */ if (gimple_call_builtin_p (stmt, BUILT_IN_STACK_RESTORE)) - gimple_set_location (stmt, UNKNOWN_LOCATION); + gimple_set_location (stmt, last_loc); else if (LOCATION_LOCUS (gimple_location (stmt)) == UNKNOWN_LOCATION) { tree block = gimple_block (stmt); gimple_set_location (stmt, loc); gimple_set_block (stmt, block); } + else + last_loc = gimple_location (stmt); } if (outer_state->tf) @@ -4751,15 +4754,9 @@ cleanup_all_empty_eh (void) eh_landing_pad lp; int i; - /* Ideally we'd walk the region tree and process LPs inner to outer - to avoid quadraticness in EH redirection. Walking the LP array - in reverse seems to be an approximation of that. */ - for (i = vec_safe_length (cfun->eh->lp_array) - 1; i >= 1; --i) - { - lp = (*cfun->eh->lp_array)[i]; - if (lp) - changed |= cleanup_empty_eh (lp); - } + for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i) + if (lp) + changed |= cleanup_empty_eh (lp); return changed; }