From patchwork Thu Feb 9 19:51:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 726312 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 3vK7xP1RGdz9s73 for ; Fri, 10 Feb 2017 06:51:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CmoBHGLN"; dkim-atps=neutral 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=gv8oXqu/JQcC4y8457LR0a3iNtq7B AhaIzXKS0RafiTGymhZp1/42MnhFG3ZcuHM8qyh3TcatzJSO+71bu2xivVMXliKM egfRyZJnf2DRdWy+aMkXaigdi+S+E1H/Akg8dvvwXBuLcvRSFJknmWMXMX69VQqn ZacI3QM4pj3XCo= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=Fis6lqbx97mIGbGCkp1S941ey3I=; b=Cmo BHGLNwgvrOssoRXNlXOKgwz1ey9SOFFcSQbmjNx29TfekjEJvJCCbkyBIt1NkqID SWCmnZJAGvWBJM59gjSX1haUfY8zucS8JO9eMrDUgerr7rKgGw1JzLOXmj0zi3zo 9RloCicCXxuKq4tiO7RnYruvX7I13McGecARJ2R8= Received: (qmail 45967 invoked by alias); 9 Feb 2017 19:51:10 -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 45952 invoked by uid 89); 9 Feb 2017 19:51:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Feb 2017 19:51:08 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 129F5C0D61CC; Thu, 9 Feb 2017 19:51:08 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v19Jp6D8005111 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 9 Feb 2017 14:51:07 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v19Jp4Ma020179; Thu, 9 Feb 2017 20:51:04 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v19Jp1li020178; Thu, 9 Feb 2017 20:51:01 +0100 Date: Thu, 9 Feb 2017 20:51:01 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid (ab) SSA_NAMEs in reassoc (PR tree-optimization/79411) Message-ID: <20170209195101.GP1849@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! This is a big hammer approach for (ab) SSA_NAME issues in reassoc, on the following testcase we extend the lifetime of (ab) SSA_NAME and ICE because it can't be coalesced anymore. In theory we could try to be careful and whenever changing something that could extend (ab) lifetime, instead insert a non-(ab) SSA_NAME to copy the (ab) SSA_NAME to at the point of use and then use the temporary later on, but after looking for a while, it would mean changing way too many places, so this patch just punts on them or stops linearing when seeing them, so the ops vectors should not contain (ab) SSA_NAMEs, the various negations/undistributions etc. should also avoid them etc. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-02-09 Jakub Jelinek PR tree-optimization/79411 * tree-ssa-reassoc.c (is_reassociable_op): Return false if stmt operands are SSA_NAMEs used in abnormal phis. (can_reassociate_p): Return false if op is SSA_NAME used in abnormal phis. * gcc.c-torture/compile/pr79411.c: New test. Jakub --- gcc/tree-ssa-reassoc.c.jj 2017-01-24 23:29:09.000000000 +0100 +++ gcc/tree-ssa-reassoc.c 2017-02-09 13:14:23.711878845 +0100 @@ -605,7 +605,18 @@ is_reassociable_op (gimple *stmt, enum t if (is_gimple_assign (stmt) && gimple_assign_rhs_code (stmt) == code && has_single_use (gimple_assign_lhs (stmt))) - return true; + { + tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs1 (stmt); + if (TREE_CODE (rhs1) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)) + return false; + if (rhs2 + && TREE_CODE (rhs2) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)) + return false; + return true; + } return false; } @@ -4989,6 +5000,8 @@ static bool can_reassociate_p (tree op) { tree type = TREE_TYPE (op); + if (TREE_CODE (op) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op)) + return false; if ((ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) || NON_SAT_FIXED_POINT_TYPE_P (type) || (flag_associative_math && FLOAT_TYPE_P (type))) --- gcc/testsuite/gcc.c-torture/compile/pr79411.c.jj 2017-02-09 13:34:06.016485562 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr79411.c 2017-02-09 13:33:53.000000000 +0100 @@ -0,0 +1,22 @@ +/* PR tree-optimization/79411 */ + +typedef struct __jmp_buf_tag { char buf[1024]; } jmp_buf[1]; +extern int setjmp (jmp_buf); +extern int bar (unsigned int *); +extern jmp_buf *baz (void); +struct C { int c1; unsigned int c2, c3, c4; }; + +void +foo (struct C *x, const int *y, unsigned int *z, unsigned int e, unsigned int g) +{ + unsigned int d = 0; + unsigned long f; + setjmp (*baz ()); + f = 1 + d; + if ((x->c1 || x->c2) && g && (!e || d >= 8)) + d = 16; + else + d = 8; + if ((!x->c3 && !x->c4 || *y == 0) && !e && bar (z)) + *z = 1 + f; +}