From patchwork Thu Mar 22 09:54:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 889272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475226-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mentor.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="InRMY5mR"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 406MT96F5Qz9s1B for ; Thu, 22 Mar 2018 20:54:20 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Vb/U+hI5chxM6NfhzX2u+is4himD7itQ37OIbm3Kv9HU5joM/F csoBRUIVcKnQltYFRn3x0XNDMe/d1HgMEy//f/zQnIXk0Izg0r/7JHgzyIOK5qF9 cTXpnkkz/HH8nw/bongsPLyvDbFDABm2dJ73PE59VYU1irJizDtHqYuVA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=C5lh0EdAYI24hyBvMU6KRgywoWE=; b=InRMY5mR7plajFTPx7jI 4Qqz10mG+CMAL1u1xr3kxJJCXkGiw6cC/m5kTtm50vILklL3KjEetrigccAWGJqX S9Li5m+updUGyuLiH9fzRuUKQLJAJxD3g3f7EP85M3GwU1KI67gWVT9B8edWhsVd gZunuL/6t66IeLWM2VE7G40= Received: (qmail 35690 invoked by alias); 22 Mar 2018 09:54:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 35676 invoked by uid 89); 22 Mar 2018 09:54:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=abnormal, 6024 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Mar 2018 09:54:11 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1eywvA-0001TE-Ru from Tom_deVries@mentor.com ; Thu, 22 Mar 2018 02:54:08 -0700 Received: from [137.202.13.181] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 22 Mar 2018 09:54:05 +0000 To: Richard Biener CC: GCC Patches From: Tom de Vries Subject: [tail-merge, PR84956] Don't merge bbs with bb_has_abnormal_pred Message-ID: <3bfab45a-2a04-e834-8af6-3390c8147347@mentor.com> Date: Thu, 22 Mar 2018 10:54:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi, This fixes a 6/7/8 regression, a P3 ICE in the tail-merge pass. Consider the test-case from the patch. When compiling at -O2, duplicates are found in tail-merge: ... find_duplicates: duplicate of find_duplicates: duplicate of ... So, tail-merge calls replace_block_by (bb7, bb6). However, bb7 has an abnormal edge bb5 -> bb7 as predecessor (bb6 has an abnormal edge as predecessor as well, but that doesn't look necessary to trigger the ICE): ... ;; basic block 9, loop depth 0 ;; prev block 3, next block 4, flags: (NEW, REACHABLE) ;; pred: 3 [50.0% (guessed)] (FALSE_VALUE,EXECUTABLE) goto ; [100.00%] ;; succ: 8 [always] (FALLTHRU,EXECUTABLE) ;; basic block 6, loop depth 0 ;; prev block 5, next block 7, flags: (NEW, REACHABLE, VISITED) ;; pred: 5 [33.3% (guessed)] (ABNORMAL,EXECUTABLE) goto ; [100.00%] ;; succ: 8 [always] (FALLTHRU,EXECUTABLE) ;; basic block 7, loop depth 0 ;; prev block 6, next block 8, flags: (NEW, REACHABLE, VISITED) ;; pred: 5 [33.3% (guessed)] (ABNORMAL,EXECUTABLE) ;; succ: 8 [always] (FALLTHRU,EXECUTABLE) ... So when replace_block_by calls redirect_edge_and_branch (bb5 -> bb7, bb6) it lands in gimple_redirect_edge_and_branch, and fails here: ... 6024 if (e->flags & EDGE_ABNORMAL) 6025 return NULL; ... which causes this assert to trigger: ... gcc_assert (pred_edge != NULL); ... The patch fixes the ICE conservatively by skipping bbs with bb_has_abnormal_preds in find_clusters_1. [ A more optimal fix could be to detect in this example that there's an abnormal edge bb5 -> bb6, and skip redirecting bb5 -> bb7 to bb6. ] Bootstrapped and reg-tested on x86_64. OK for stage4, gcc-6-branch and gcc-7-branch? Thanks, - Tom [tail-merge] Don't merge bbs with bb_has_abnormal_pred 2018-03-21 Tom de Vries PR tree-optimization/84956 * tree-ssa-tail-merge.c (find_clusters_1): Skip bbs with bb_has_abnormal_pred. * gcc.dg/pr84956.c: New test. --- gcc/testsuite/gcc.dg/pr84956.c | 27 +++++++++++++++++++++++++++ gcc/tree-ssa-tail-merge.c | 6 ++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr84956.c b/gcc/testsuite/gcc.dg/pr84956.c new file mode 100644 index 0000000..055a749 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84956.c @@ -0,0 +1,27 @@ +/* { dg-options "-O2 -ftree-tail-merge" } */ + +char a; +int c; +unsigned b (); + +unsigned +setjmp () +{ +} + +static void +d () +{ + if (b ()) + c = 3; +} + +void +e () +{ + d (); + a && ({ setjmp (); }); + a && ({ setjmp (); }); + a && ({ setjmp (); }); +} + diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c index a687c3f..f482ce1 100644 --- a/gcc/tree-ssa-tail-merge.c +++ b/gcc/tree-ssa-tail-merge.c @@ -1455,7 +1455,8 @@ find_clusters_1 (same_succ *same_succ) /* TODO: handle blocks with phi-nodes. We'll have to find corresponding phi-nodes in bb1 and bb2, with the same alternatives for the same preds. */ - if (bb_has_non_vop_phi (bb1) || bb_has_eh_pred (bb1)) + if (bb_has_non_vop_phi (bb1) || bb_has_eh_pred (bb1) + || bb_has_abnormal_pred (bb1)) continue; nr_comparisons = 0; @@ -1463,7 +1464,8 @@ find_clusters_1 (same_succ *same_succ) { bb2 = BASIC_BLOCK_FOR_FN (cfun, j); - if (bb_has_non_vop_phi (bb2) || bb_has_eh_pred (bb2)) + if (bb_has_non_vop_phi (bb2) || bb_has_eh_pred (bb2) + || bb_has_abnormal_pred (bb2)) continue; if (BB_CLUSTER (bb1) != NULL && BB_CLUSTER (bb1) == BB_CLUSTER (bb2))