From patchwork Sat Nov 9 16:30:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 290003 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 371BD2C00A9 for ; Sun, 10 Nov 2013 03:30:32 +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:cc:subject:content-type; q=dns; s=default; b=x5/x2i4eV7NpVnlOAg+a7mmVExtdKOWnURA2BdbIdF/ yYvhaJOB7iWZbrQ8R5jbPyS3OSt42FEf+39Lktxm+iDP7jzgxzK/HZXca+MuERrE A9JfqtpzPaF/7RvBTHan5oNSdKSYK3V5qinc3h9UmQR3kdtti5Zi8DomLsGfByy4 = 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:cc:subject:content-type; s=default; bh=8z2l7Wm2fFW5rMnyllXEQ9dG0Jc=; b=DAxNBgIYSb2aWTu/U zCLUG9ULPn9O37Qyw35ExKp1aYppQTlrTfxpn2a2fXcLHtpvhL48DcRHhVltVMAp QuI+835lYKqnm0hteLZvpJj3btmNX6trQehFeRRO0YlIWHIniC9CC4A9L9WvXq0Q iizaGfHo+S7ApS1oj9FHlYu604= Received: (qmail 26632 invoked by alias); 9 Nov 2013 16:30:23 -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 26622 invoked by uid 89); 9 Nov 2013 16:30:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Nov 2013 16:30:21 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VfBQD-00025X-7z from Tom_deVries@mentor.com ; Sat, 09 Nov 2013 08:30:05 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sat, 9 Nov 2013 08:30:04 -0800 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Sat, 9 Nov 2013 16:30:02 +0000 Message-ID: <527E6308.6030104@mentor.com> Date: Sat, 9 Nov 2013 17:30:00 +0100 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Richard Biener CC: Subject: [PATCH] Handle GIMPLE_ASSIGNs with different vuse in gimple_equal_p Richard, Consider the test-case test.c: ... int z; int x; void f (int c, int d) { if (c) z = 5; else { if (d) x = 4; z = 5; } } ... Atm, we don't tail-merge the 'z = 5' blocks, because gimple_equal_p returns false for the 'z = 5' statements. The relevant code is this: ... if (TREE_CODE (lhs1) != SSA_NAME && TREE_CODE (lhs2) != SSA_NAME) return (vn_valueize (gimple_vdef (s1)) == vn_valueize (gimple_vdef (s2))); ... The vdefs of the 'z = 5' statements are different, because the incoming vuses are different. This patch handles GIMPLE_ASSIGNs with different vuse in gimple_equal_p, by doing a structural comparison. Bootstrapped and regtested on x86_64. OK for trunk? Thanks, - Tom 2013-11-06 Tom de Vries * tree-ssa-tail-merge.c (gimple_equal_p): Add test for structural equality for GIMPLE_ASSIGN. * gcc.dg/tail-merge-store.c: New test. diff --git a/gcc/testsuite/gcc.dg/tail-merge-store.c b/gcc/testsuite/gcc.dg/tail-merge-store.c new file mode 100644 index 0000000..1aefbdc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tail-merge-store.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-tail-merge -fdump-tree-pre" } */ + +int z; +int x; + +void +f (int c, int d) +{ + if (c) + z = 5; + else + { + if (d) + x = 4; + z = 5; + } +} + +/* { dg-final { scan-tree-dump-times "duplicate of" 1 "pre"} } */ +/* { dg-final { scan-tree-dump-times "z = 5" 1 "pre"} } */ +/* { dg-final { cleanup-tree-dump "pre" } } */ diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c index 98b5882..43516a7 100644 --- a/gcc/tree-ssa-tail-merge.c +++ b/gcc/tree-ssa-tail-merge.c @@ -1173,8 +1173,47 @@ gimple_equal_p (same_succ same_succ, gimple s1, gimple s2) lhs2 = gimple_get_lhs (s2); if (TREE_CODE (lhs1) != SSA_NAME && TREE_CODE (lhs2) != SSA_NAME) - return (vn_valueize (gimple_vdef (s1)) - == vn_valueize (gimple_vdef (s2))); + { + /* If the vdef is the same, it's the same statement. */ + if (vn_valueize (gimple_vdef (s1)) + == vn_valueize (gimple_vdef (s2))) + return true; + + /* If the vdef is not the same but the vuse is the same, it's not the + same stmt. */ + if (vn_valueize (gimple_vuse (s1)) + == vn_valueize (gimple_vuse (s2))) + return false; + /* If the vdef is not the same and the vuse is not the same, it might be + same stmt. */ + + /* Test for structural equality. */ + if (gimple_assign_rhs_code (s1) != gimple_assign_rhs_code (s1) + || (gimple_assign_nontemporal_move_p (s1) + != gimple_assign_nontemporal_move_p (s2))) + return false; + + if (!operand_equal_p (lhs1, lhs2, 0)) + return false; + + t1 = gimple_assign_rhs1 (s1); + t2 = gimple_assign_rhs1 (s2); + if (!gimple_operand_equal_value_p (t1, t2)) + return false; + + t1 = gimple_assign_rhs2 (s1); + t2 = gimple_assign_rhs2 (s2); + if (!gimple_operand_equal_value_p (t1, t2)) + return false; + + t1 = gimple_assign_rhs3 (s1); + t2 = gimple_assign_rhs3 (s2); + if (!gimple_operand_equal_value_p (t1, t2)) + return false; + + /* Same structure. */ + return true; + } else if (TREE_CODE (lhs1) == SSA_NAME && TREE_CODE (lhs2) == SSA_NAME) return vn_valueize (lhs1) == vn_valueize (lhs2);