From patchwork Fri Feb 13 23:50:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 439688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 EC0AE140271 for ; Sat, 14 Feb 2015 10:51:46 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=GJiBdT/b7DEmZiwBEsMSC9Z6GqHQnl9F2QiMiKDq7VSdyYrXpJU2x eHbKjzo6zq1koAwhkGUg5cTrh7fWRE+EiYq2bs0QCGaazzkGGGLrax42R6XwHkys eIkXYsEIifQAz8bGCuS1h1KlhKxnIgq8JOYOoH67rIhs9kbyCRNErQ= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=JvxHD9sEMAjRtJhV2P3vh6BlLkg=; b=F5TXUoPY+wBjuWyLwSJc OoEtjNDlMvhrDkq49hKjyJjTodYsUd17R57gCf47XvcMmfGEH8xhsaXd5jD/9hEg 6pXv4dBBLucLbD1n1q8VByqVaexJMkq9UPrx95I7uVT+cVrxCXSdIMwIkSVQhIDc aNBVjBohqJt+5oa1+ee2mqo= Received: (qmail 876 invoked by alias); 13 Feb 2015 23:50:40 -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 800 invoked by uid 89); 13 Feb 2015 23:50:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ie0-f170.google.com Received: from mail-ie0-f170.google.com (HELO mail-ie0-f170.google.com) (209.85.223.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 13 Feb 2015 23:50:38 +0000 Received: by iecar1 with SMTP id ar1so23242054iec.11 for ; Fri, 13 Feb 2015 15:50:36 -0800 (PST) X-Received: by 10.107.11.17 with SMTP id v17mr7115611ioi.74.1423871436254; Fri, 13 Feb 2015 15:50:36 -0800 (PST) Received: from f1.c.bardezibar.internal (81.37.148.146.bc.googleusercontent.com. [146.148.37.81]) by mx.google.com with ESMTPSA id c6sm5320555ioe.37.2015.02.13.15.50.35 (version=SSLv3 cipher=RC4-SHA bits=128/128); Fri, 13 Feb 2015 15:50:35 -0800 (PST) Date: Fri, 13 Feb 2015 23:50:33 +0000 From: Sebastian Pop To: gcc-patches@gcc.gnu.org, Jeff Law Subject: [patch] fix PR65048: check that jump-thread paths are still valid Message-ID: <20150213235033.GA20179@f1.c.bardezibar.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, the attached patch fixes PR65048 by checking before jump-threading that a path to be threaded is still valid: as the testcase shows, there may be paths that are not connected anymore because the cfg has changed in a previous jump-thread. PR tree-optimization/65048 * tree-ssa-threadupdate.c (valid_jump_thread_path): New. (thread_through_all_blocks): Call valid_jump_thread_path. Remove invalid FSM jump-thread paths. * gcc.dg/tree-ssa/ssa-dom-thread-9.c: New. The patch passed bootstrap and regression tests on x86_64-linux. Ok for trunk? Thanks, Sebastian From 79b93a743649b898010cfea70769184bca28efb1 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Tue, 10 Feb 2015 22:36:50 +0100 Subject: [PATCH] check that paths are still valid to be threaded PR tree-optimization/65048 * tree-ssa-threadupdate.c (valid_jump_thread_path): New. (thread_through_all_blocks): Call valid_jump_thread_path. Remove invalid FSM jump-thread paths. * gcc.dg/tree-ssa/ssa-dom-thread-9.c: New. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c | 49 ++++++++++++++++++++++ gcc/tree-ssa-threadupdate.c | 40 +++++++++++++++--- 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c new file mode 100644 index 0000000..a843753 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +int a, b, c, d; +void fn (void); + +int +foo (x) +{ + switch (x) + { + case 'A': + return 'T'; + case 'U': + return 'A'; + } +} + +void +bar (int x, int y) +{ + switch (c) + { + case 'U': + switch (x) + { + default: + fn (); + case 'G': + switch (y) + { + case 'A': + d = 7; + } + } + } +} + +void +baz (void) +{ + while (1) + { + a = foo (); + b = foo (); + bar (a, b); + } +} + diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 3326144..7a41ab2 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -2473,6 +2473,21 @@ duplicate_seme_region (edge entry, edge exit, return true; } +/* Return true when PATH is a valid jump-thread path. */ + +static bool +valid_jump_thread_path (vec *path) +{ + unsigned len = path->length (); + + /* Check that the path is connected. */ + for (unsigned int j = 0; j < len - 1; j++) + if ((*path)[j]->e->dest != (*path)[j+1]->e->src) + return false; + + return true; +} + /* Walk through all blocks and thread incoming edges to the appropriate outgoing edge for each edge pair recorded in THREADED_EDGES. @@ -2505,12 +2520,25 @@ thread_through_all_blocks (bool may_peel_loop_headers) vec *path = paths[i]; edge entry = (*path)[0]->e; - if ((*path)[0]->type != EDGE_FSM_THREAD - /* Do not jump-thread twice from the same block. */ - || bitmap_bit_p (threaded_blocks, entry->src->index)) { - i++; - continue; - } + /* Only code-generate FSM jump-threads in this loop. */ + if ((*path)[0]->type != EDGE_FSM_THREAD) + { + i++; + continue; + } + + /* Do not jump-thread twice from the same block. */ + if (bitmap_bit_p (threaded_blocks, entry->src->index) + /* Verify that the jump thread path is still valid: a + previous jump-thread may have changed the CFG, and + invalidated the current path. */ + || !valid_jump_thread_path (path)) + { + /* Remove invalid FSM jump-thread paths. */ + delete_jump_thread_path (path); + paths.unordered_remove (i); + continue; + } unsigned len = path->length (); edge exit = (*path)[len - 1]->e; -- 1.7.2.5