From patchwork Thu Jan 7 21:41:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 564466 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 000A21402F0 for ; Fri, 8 Jan 2016 08:41:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=uptzZt9m; 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=QZgd6v9oKf6KCPWH2SSXeVfyuRznx +Alfk6R8hsLA5LxULFD/RVTTwXVqhBSUx06fvU0Dsbj0pWN8jbg+76WZX9QC1ePs GUvL1kK5nrv9b9zUnw1YOaEw/RV0DepQ5nBOOyEV1rSYi1/rs0tybJb96K3IQq0t qerIhIKjUugzF0= 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=I9Hm6rG0FCyFBnBVyyuFWewNYOU=; b=upt zZt9mW+x5v8wezT/UsknvT8iM4NHOlCAmvv3c0muxquR2e8S8HDtAj3tVPZFXQI5 mm2x7GuRdR6kzsrtz1WFNYkwe8UKbS5bH9KV9U9W4vxGb24/lwqv/21m+7Z3z+tq VTDfbeu/phcMO1QWITeWt9uZjWae9HOpBYEfiGzI= Received: (qmail 105442 invoked by alias); 7 Jan 2016 21:41:25 -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 105420 invoked by uid 89); 7 Jan 2016 21:41:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=347, 34, 7, 1, 21, UD:gimple-fold.c.jj 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 07 Jan 2016 21:41:23 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 9F41191FD5; Thu, 7 Jan 2016 21:41:22 +0000 (UTC) Received: from tucnak.zalov.cz ([10.3.113.3]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u07LfLFX025786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 7 Jan 2016 16:41:22 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u07LfI8v025642; Thu, 7 Jan 2016 22:41:19 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u07LfHNE025641; Thu, 7 Jan 2016 22:41:17 +0100 Date: Thu, 7 Jan 2016 22:41:17 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix (ab) SSA_NAME issue in gimple folding (PR tree-optimization/69167) Message-ID: <20160107214117.GO18720@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! Various places check that (ab) SSA_NAMEs that weren't referenced on a stmt before don't appear on it, but all the checking is done on the gimple tuple operands, while in this case it is added to operands of a comparison of COND_EXPR/VEC_COND_EXPR. The following patch fixes it, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-01-07 Jakub Jelinek PR tree-optimization/69167 * gimple-match-head.c (gimple_simplify) : Don't simplify condition if the condition simplification would introduce use of SSA_NAME_OCCURS_IN_ABNORMAL_PHI SSA_NAME not previously mentioned on the insn. * gimple-fold.h (has_use_on_stmt): New prototype. * gimple-fold.c (has_use_on_stmt): No longer static. * gcc.dg/pr69167.c: New test. Jakub --- gcc/gimple-match-head.c.jj 2016-01-04 14:55:53.000000000 +0100 +++ gcc/gimple-match-head.c 2016-01-07 12:54:42.237334530 +0100 @@ -655,9 +655,23 @@ gimple_simplify (gimple *stmt, valueized = true; if (TREE_CODE_CLASS ((enum tree_code)rcode2) == tcc_comparison) - rhs1 = build2 (rcode2, TREE_TYPE (rhs1), - ops2[0], ops2[1]); - else if (rcode2 == SSA_NAME + { + if (TREE_CODE (ops2[0]) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[0]) + && !has_use_on_stmt (ops2[0], stmt)) + valueized = false; + if (TREE_CODE (ops2[1]) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops2[1]) + && !has_use_on_stmt (ops2[1], stmt)) + valueized = false; + if (valueized) + rhs1 = build2 (rcode2, TREE_TYPE (rhs1), + ops2[0], ops2[1]); + } + else if ((rcode2 == SSA_NAME + && (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI + (ops2[0]) + || has_use_on_stmt (ops2[0], stmt))) || rcode2 == INTEGER_CST || rcode2 == VECTOR_CST) rhs1 = ops2[0]; --- gcc/gimple-fold.h.jj 2016-01-04 14:55:53.000000000 +0100 +++ gcc/gimple-fold.h 2016-01-07 13:01:52.938315972 +0100 @@ -34,6 +34,7 @@ extern tree maybe_fold_or_comparisons (e enum tree_code, tree, tree); extern bool arith_overflowed_p (enum tree_code, const_tree, const_tree, const_tree); +extern bool has_use_on_stmt (tree, gimple *); extern tree no_follow_ssa_edges (tree); extern tree follow_single_use_edges (tree); extern tree gimple_fold_stmt_to_constant_1 (gimple *, tree (*) (tree), --- gcc/gimple-fold.c.jj 2016-01-07 11:37:36.000000000 +0100 +++ gcc/gimple-fold.c 2016-01-07 13:01:25.793695288 +0100 @@ -3270,7 +3270,7 @@ gimple_fold_call (gimple_stmt_iterator * /* Return true whether NAME has a use on STMT. */ -static bool +bool has_use_on_stmt (tree name, gimple *stmt) { imm_use_iterator iter; --- gcc/testsuite/gcc.dg/pr69167.c.jj 2016-01-07 12:58:40.706002201 +0100 +++ gcc/testsuite/gcc.dg/pr69167.c 2016-01-07 12:58:22.000000000 +0100 @@ -0,0 +1,21 @@ +/* PR tree-optimization/69167 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int sigsetjmp (char *); +void foo (); +void bar (void (*) (int *)); +extern char t[]; + +void +baz (int *x) +{ + int *a = x; + foo (); + x = 0; + if (sigsetjmp (t)) + while (1) + bar (a ? baz : 0); + if (x) + foo (); +}