From patchwork Tue Dec 3 03:45:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 296061 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 70ACD2C0092 for ; Tue, 3 Dec 2013 14:46:08 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=QUDGtgZk1ssnU/Z0YO8LwD0oQKNlf/KJOGyq7J6zO5uJRM xwEu6R/6C9bxAU6ap3vA/zPueAW4tYqPjlI0n0QBzq+OgiwBtXQVRUu6ckflTAJg sUGQfb0oPYKrwgkpx5ZkzIoV+c6baGKHUSuVr/vIJv0pvO96lKfsFEoWHqoBs= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=iTjic6s3PD3P5KP5uqe8S4atNlg=; b=x0zUmHIeXC5uAK/ovJCY 6A+3b+CkWCC6CtpOIVgGqG24VCuvgF1GimyVI93/VAfdnpkGeygtS+Fzi9q0vwQC 69mvg8pHO9TOe/6wtDekWCrKLSFj3Ws9TZyDVe2LkowLyHd+qKNwViAJVIDInt1R a5Twpg/ikGDXUu20uTwpZQI= Received: (qmail 20979 invoked by alias); 3 Dec 2013 03:45:58 -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 20970 invoked by uid 89); 3 Dec 2013 03:45:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_00, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2013 03:45:55 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rB33jm65012397 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 2 Dec 2013 22:45:48 -0500 Received: from stumpy.slc.redhat.com (ovpn-113-152.phx2.redhat.com [10.3.113.152]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rB33jlON019508 for ; Mon, 2 Dec 2013 22:45:48 -0500 Message-ID: <529D53EB.6000309@redhat.com> Date: Mon, 02 Dec 2013 20:45:47 -0700 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] [PR tree-optimization/59322] Remove unwanted jump thread path copying X-IsSubscribed: yes Code was added to copy the jump threading path (AUX field on an edge) by a change from Zdenek in 2007. At the time the code was added, AFAICT, the copied AUX field would never be examined and certainly not used for threading. I'd been suspicious of Zdenek's code to copy the AUX field, but went along with it and changed it to properly copy the updated representation. The testcase for 59322 is wonderful in that it shows how that copying is just plan bad because it results in dangling embedded edge pointers in the jump threading path. We make the copy and attach it to a new edge's AUX field in the CFG. We then thread from outside the loop through the loop header. We can delete edges in the CFG as a result. This leaves a dangling edge pointer in a the jump threading path structure (particularly the copied one). We then walk all the edges to see if any are threads from inside the loop, through the backedge to another point within the loop. This may reference the jump threading path containing the dangling edge pointer. As I mentioned, I went back and looked at the 2007 code and AFAICT copying the AUX field was dead when it was added. This patch removes the code to copy the jump threading path in the AUX field to newly created edges. And (of course), it fixes the 59322 testcase. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. Installed on the trunk. Jeff PR tree-optimization/59322 * tree-ssa-threadedge.c (create_edge_and_update_destination_phis): Remove code which copied jump threading paths. PR tree-optimization/59322 * gcc.c-torture/compile/pr59322.c: New test diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 24d0f42..ad727a1 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -421,27 +421,22 @@ create_edge_and_update_destination_phis (struct redirection_data *rd, e->probability = REG_BR_PROB_BASE; e->count = bb->count; - /* We have to copy path -- which means creating a new vector as well - as all the jump_thread_edge entries. */ - if (rd->path->last ()->e->aux) - { - vec *path = THREAD_PATH (rd->path->last ()->e); - vec *copy = new vec (); + /* We used to copy the thread path here. That was added in 2007 + and dutifully updated through the representation changes in 2013. - /* Sadly, the elements of the vector are pointers and need to - be copied as well. */ - for (unsigned int i = 0; i < path->length (); i++) - { - jump_thread_edge *x - = new jump_thread_edge ((*path)[i]->e, (*path)[i]->type); - copy->safe_push (x); - } - e->aux = (void *)copy; - } - else - { - e->aux = NULL; - } + In 2013 we added code to thread from an interior node through + the backedge to another interior node. That runs after the code + to thread through loop headers from outside the loop. + + The latter may delete edges in the CFG, including those + which appeared in the jump threading path we copied here. Thus + we'd end up using a dangling pointer. + + After reviewing the 2007/2011 code, I can't see how anything + depended on copying the AUX field and clearly copying the jump + threading path is problematical due to embedded edge pointers. + It has been removed. */ + e->aux = NULL; /* If there are any PHI nodes at the destination of the outgoing edge from the duplicate block, then we will need to add a new argument