From patchwork Tue Aug 13 08:33:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1146128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506779-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XFa9jIeb"; dkim-atps=neutral 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 4675fb2Ydkz9sNF for ; Tue, 13 Aug 2019 18:36:39 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=JwxlYg3GPWC/Y02bkGOw9FNWt/O0iqOaCcQcNDqD7X0snR5A8BpiA ZsSxm0p+Gh1tG90rAQ7S52olGZLrqXtVhNBatu63bIg7Eq/KdA5fWRZD7LOGmCBx M+ecubFKQ2UtpobfDcJgV+jFDA2zygum3xu9Azgc+AAYkDMzwYmwBM= 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:from :to:subject:date:in-reply-to:references:message-id; s=default; bh=aF3wQr7rtKvxdHfGu08sxNPQdQE=; b=XFa9jIebxghnu+OqqEQcAAaahVX+ Vtjb/GeKGc0UjkzGgsBiIO8jE5+/GD/N9PvLtl7Bw0eorLB1tBjlG3LUZQWOkF0A T+t4vSmicqqz81i8DLSOhh055NcJU5PAgcJldfKeDAUziAN065Xejg6LSw2nqpsf Va/7dKvJ9hF0zKA= Received: (qmail 121966 invoked by alias); 13 Aug 2019 08:33:38 -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 121828 invoked by uid 89); 13 Aug 2019 08:33:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=dse2 X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Aug 2019 08:33:34 +0000 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7D8X7kX194826 for ; Tue, 13 Aug 2019 04:33:32 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ubryq22k3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Aug 2019 04:33:32 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Aug 2019 09:33:30 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 13 Aug 2019 09:33:28 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7D8XRcQ8519838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Aug 2019 08:33:27 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AF85A405F for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44F38A405B for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.152.222.26]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] Perform fold when propagating. Date: Tue, 13 Aug 2019 10:33:24 +0200 In-Reply-To: <20190813083326.10833-1-rdapp@linux.ibm.com> References: <20190813083326.10833-1-rdapp@linux.ibm.com> x-cbid: 19081308-0008-0000-0000-00000308721D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19081308-0009-0000-0000-00004A2683C7 Message-Id: <20190813083326.10833-2-rdapp@linux.ibm.com> X-IsSubscribed: yes This patch performs more aggressive folding in order for the match.pd changes to kick in later. Some test cases rely on VRP doing something which now already happens during CCP so adjust them accordingly. Also, the loop versioning pass was missing one case when deconstructing addresses that would only be triggered after this patch for me: It could handle addition and subsequent convert/nop but not a convert/nop directly. This would cause the hash to be calculated differently and, in turn, cause the pass to miss a versioning opportunity. Fixed this by adding the missing case. --- gcc/fortran/trans-intrinsic.c | 5 +++-- gcc/gimple-loop-versioning.cc | 6 ++++++ gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C | 4 +++- gcc/testsuite/gcc.dg/pr35691-1.c | 4 ++-- gcc/testsuite/gcc.dg/pr35691-2.c | 4 ++-- gcc/testsuite/gcc.dg/pr35691-3.c | 4 ++-- gcc/testsuite/gcc.dg/pr35691-4.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/loop-15.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr23744.c | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/pr52631.c | 4 ++-- gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c | 2 +- gcc/tree-ssa-propagate.c | 6 ++++-- 15 files changed, 36 insertions(+), 25 deletions(-) diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index a6e33833680..99ec5f34319 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -5428,8 +5428,9 @@ gfc_conv_intrinsic_findloc (gfc_se *se, gfc_expr *expr) tree type; tree tmp; tree found; - tree forward_branch; - tree back_branch; + /* Initialize here to avoid 'maybe used uninitialized'. */ + tree forward_branch = NULL_TREE; + tree back_branch = NULL_TREE; gfc_loopinfo loop; gfc_ss *arrayss; gfc_ss *maskss; diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc index 8fa19488490..36c70543402 100644 --- a/gcc/gimple-loop-versioning.cc +++ b/gcc/gimple-loop-versioning.cc @@ -1266,6 +1266,12 @@ loop_versioning::record_address_fragment (gimple *stmt, continue; } } + if (code == NOP_EXPR) + { + tree op1 = gimple_assign_rhs1 (assign); + address->terms[i].expr = strip_casts (op1); + continue; + } } i += 1; } diff --git a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C index ca7e18f66a9..83a8f0668df 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C +++ b/gcc/testsuite/g++.dg/tree-ssa/ssa-dse-2.C @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-dse2-details -Wno-return-type" } */ +/* { dg-options "-O2 -fdump-tree-dse2-details -fdump-tree-vrp1-details -Wno-return-type" } */ typedef __SIZE_TYPE__ size_t; extern "C" @@ -55,3 +55,5 @@ fill_vec_av_set (av_set_t av) /* { dg-final { scan-tree-dump-not "Trimming statement .head = -" "dse2" } } */ /* { dg-final { scan-tree-dump-not "mem\[^\r\n\]*, 0\\);" "dse2" } } */ +/* { dg-final { scan-tree-dump "Folded into: GIMPLE_NOP" "vrp1" } } */ +/* { dg-final { scan-tree-dump-not "memmove" "dse2" } } */ } diff --git a/gcc/testsuite/gcc.dg/pr35691-1.c b/gcc/testsuite/gcc.dg/pr35691-1.c index 34dc02ab560..2e1d8bd0f43 100644 --- a/gcc/testsuite/gcc.dg/pr35691-1.c +++ b/gcc/testsuite/gcc.dg/pr35691-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details" } */ int foo(int z0, unsigned z1) { @@ -9,4 +9,4 @@ int foo(int z0, unsigned z1) return t2; } -/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-2.c b/gcc/testsuite/gcc.dg/pr35691-2.c index b89ce481c6c..d5e335bb72a 100644 --- a/gcc/testsuite/gcc.dg/pr35691-2.c +++ b/gcc/testsuite/gcc.dg/pr35691-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details" } */ int foo(int z0, unsigned z1) { @@ -9,4 +9,4 @@ int foo(int z0, unsigned z1) return t2; } -/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-3.c b/gcc/testsuite/gcc.dg/pr35691-3.c index 75b49a6e2ca..a1896e47b59 100644 --- a/gcc/testsuite/gcc.dg/pr35691-3.c +++ b/gcc/testsuite/gcc.dg/pr35691-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details" } */ int foo(int z0, unsigned z1) { @@ -9,4 +9,4 @@ int foo(int z0, unsigned z1) return t2; } -/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr35691-4.c b/gcc/testsuite/gcc.dg/pr35691-4.c index 2d9456bd16f..58f28aebe69 100644 --- a/gcc/testsuite/gcc.dg/pr35691-4.c +++ b/gcc/testsuite/gcc.dg/pr35691-4.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-forwprop1-details" } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details" } */ int foo(int z0, unsigned z1) { @@ -9,4 +9,4 @@ int foo(int z0, unsigned z1) return t2; } -/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "gimple_simplified to _\[0-9\]* = \\(int\\) z1_\[0-9\]*\\(D\\);" "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c index 10935293476..17c2a7e2d3e 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-dce2 -fdump-tree-forwprop1-details" } */ +/* { dg-options "-O2 -fdump-tree-dce2 -fdump-tree-ccp1-details" } */ int abarney[2]; int afred[1]; @@ -23,7 +23,7 @@ void foo(int edx, int eax) /* Verify that we did a forward propagation. */ -/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "forwprop1"} } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "ccp1"} } */ /* After dce we should have two IF statements remaining as the other two tests can be threaded. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c b/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c index b563f5e404c..6890d0067b6 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/bit-assoc.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -fdump-tree-forwprop1-details -fdump-tree-ccp1-details" } */ +/* { dg-options "-O -fdump-tree-ccp1-details" } */ int f1(int a, int b){ int c = a & b; @@ -26,4 +26,4 @@ int g3(int a, int b, int c){ } /* { dg-final { scan-tree-dump-times "Match-and-simplified" 2 "ccp1" } } */ -/* { dg-final { scan-tree-dump-times "gimple_simplified" 3 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified" 3 "ccp1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c index 1bef7e7a31f..bef76e597dd 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-16.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -fdump-tree-forwprop1" } */ +/* { dg-options "-O -fdump-tree-forwprop2" } */ int foo (double xx, double xy) { @@ -10,4 +10,4 @@ int foo (double xx, double xy) return 2; } -/* { dg-final { scan-tree-dump "if \\\(x" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "if \\\(x" "forwprop2" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c index b437518487d..dce6ad57a04 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-15.c @@ -19,7 +19,7 @@ int bla(void) } /* Since the loop is removed, there should be no addition. */ -/* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" } } */ /* { dg-final { scan-tree-dump-times " \\* " 1 "optimized" } } */ /* The if from the loop header copying remains in the code. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c b/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c index 3385aa1e424..ba3fda352ca 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1" } */ +/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1-details" } */ void h (void); @@ -17,4 +17,4 @@ int g (int i, int j) return 1; } -/* { dg-final { scan-tree-dump-times "Folding predicate.*to 1" 1 "vrp1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "vrp1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c index c18a5d570b4..2e99d112057 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-fre1-details" } */ +/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-ccp1-details" } */ unsigned f(unsigned a) { @@ -12,6 +12,6 @@ unsigned f(unsigned a) } /* We want to verify that we replace the b & 1 with b. */ -/* { dg-final { scan-tree-dump-times "Replaced b_\[0-9\]+ & 1 with b_\[0-9\]+ in" 1 "fre1"} } */ +/* { dg-final { scan-tree-dump-times "Match-and-simplified b_\[0-9\]+ & 1 to b_\[0-9\]+" 1 "ccp1"} } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c b/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c index 34ce512f372..e2e0d6cb8bc 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c +++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-23.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-additional-options "-fno-tree-forwprop -fno-tree-vrp" } +/* { dg-additional-options "-fno-tree-forwprop -fno-tree-vrp -fno-tree-ccp -fno-tree-copy-prop" } */ /* { dg-require-effective-target vect_int } */ #include "tree-vect.h" diff --git a/gcc/tree-ssa-propagate.c b/gcc/tree-ssa-propagate.c index 0862f83e9a1..7a8f1e037b0 100644 --- a/gcc/tree-ssa-propagate.c +++ b/gcc/tree-ssa-propagate.c @@ -1064,10 +1064,12 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb) /* Replace real uses in the statement. */ did_replace |= substitute_and_fold_engine->replace_uses_in (stmt); - /* If we made a replacement, fold the statement. */ if (did_replace) + gimple_set_modified (stmt, true); + + if (fold_stmt (&i, follow_single_use_edges)) { - fold_stmt (&i, follow_single_use_edges); + did_replace = true; stmt = gsi_stmt (i); gimple_set_modified (stmt, true); } From patchwork Tue Aug 13 08:33:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1146127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506778-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="gAHPp4tF"; dkim-atps=neutral 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 4675fL25fZz9sNy for ; Tue, 13 Aug 2019 18:36:26 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=dkwoNMD4P9G99I9jvvRik2pz3jXvw6dy3Po8G8J8JUEWItj6MkxL7 3o4HYbLQ1ObGUJ+hU4hVjcY6lNWcmLB8XwZvpNhiHdPeUaiS+q10zTnytobjbYIB PPT+xL1+vPg+PmM10rnIC8cfV6jTv4G5VdAfWJ5hSVllAqX/hphNCE= 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:from :to:subject:date:in-reply-to:references:message-id; s=default; bh=K8SVKaJpR3suMmugDmDTVkUx/jk=; b=gAHPp4tFSo+01Q5uzkouPeR0v49x yQffpZHeX/rVqqJKO35BPzIsuBQftSaaiFXBO40sZbv1oNZWTugsnCsCrcUnhMJy c/VqOfwOm/vGi8Mm4PZrTXJ02OaW4uCljF3JKFtS1dL0ApY2rjZrGV4YNDBDzf6F xb1YJCBvmdPuEPk= Received: (qmail 121759 invoked by alias); 13 Aug 2019 08:33:36 -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 121656 invoked by uid 89); 13 Aug 2019 08:33:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Aug 2019 08:33:34 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7D8X8Gq055132 for ; Tue, 13 Aug 2019 04:33:32 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ubrcrup46-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Aug 2019 04:33:32 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Aug 2019 09:33:30 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 13 Aug 2019 09:33:28 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7D8XR5l8519840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Aug 2019 08:33:27 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94490A405B for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77412A4064 for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.152.222.26]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] Add simplify rules for wrapped binary operations. Date: Tue, 13 Aug 2019 10:33:25 +0200 In-Reply-To: <20190813083326.10833-1-rdapp@linux.ibm.com> References: <20190813083326.10833-1-rdapp@linux.ibm.com> x-cbid: 19081308-0020-0000-0000-0000035F14C8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19081308-0021-0000-0000-000021B427EF Message-Id: <20190813083326.10833-3-rdapp@linux.ibm.com> X-IsSubscribed: yes We would like to simplify code like (larger_type)(var + const1) + const2 to (larger_type)(var + combined_const1_const2) when we know that no overflow happens. --- gcc/match.pd | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 0317bc704f7..94400529ad8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2020,6 +2020,107 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cst && !TREE_OVERFLOW (cst)) (plus { cst; } @0)))) +/* ((T)(A + CST1)) + CST2 -> (T)(A) + CST */ +#if GIMPLE + (simplify + (plus (convert (plus @0 INTEGER_CST@1)) INTEGER_CST@2) + (if (INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0))) + /* We actually want to perform two simplifications here: + (1) (T)(A + CST1) + CST2 --> (T)(A) + (T)(CST1) + If for (A + CST1) we either do not care about overflow (e.g. + for a signed inner type) or the overflow is ok for an unsigned + inner type. + (2) (T)(A) + (T)(CST1) + CST2 --> (T)(A) + (T)(CST1 + CST2) + If (CST1 + CST2) does not overflow and we do care about overflow + (for a signed outer type) or we do not care about overflow in an + unsigned outer type. */ + (with + { + tree inner_type = TREE_TYPE (@0); + wide_int wmin0, wmax0; + wide_int cst1 = wi::to_wide (@1); + + wi::overflow_type min_ovf = wi::OVF_OVERFLOW, + max_ovf = wi::OVF_OVERFLOW; + + /* Get overflow behavior. */ + bool ovf_undef_inner = TYPE_OVERFLOW_UNDEFINED (inner_type); + bool ovf_undef_outer = TYPE_OVERFLOW_UNDEFINED (type); + + /* Get value range of A. */ + enum value_range_kind vr0 = get_range_info (@0, &wmin0, &wmax0); + + /* If we have a proper range, determine min and max overflow + of (A + CST1). + ??? We might also want to handle anti ranges. */ + if (vr0 == VR_RANGE) + { + wi::add (wmin0, cst1, TYPE_SIGN (inner_type), &min_ovf); + wi::add (wmax0, cst1, TYPE_SIGN (inner_type), &max_ovf); + } + + /* Inner overflow does not matter in this case. */ + if (ovf_undef_inner) + { + min_ovf = wi::OVF_NONE; + max_ovf = wi::OVF_NONE; + } + + /* Extend CST from INNER_TYPE to TYPE. */ + cst1 = cst1.from (cst1, TYPE_PRECISION (type), TYPE_SIGN (inner_type)); + + /* Check for overflow of (TYPE)(CST1 + CST2). */ + wi::overflow_type outer_ovf = wi::OVF_OVERFLOW; + wide_int cst = wi::add (cst1, wi::to_wide (@2), TYPE_SIGN (type), + &outer_ovf); + + /* We *do* care about an overflow here as we do not want to introduce + new undefined behavior that was not there before. */ + if (ovf_undef_outer && outer_ovf) + { + /* Set these here to prevent the final conversion below + to take place instead of introducing a new guard variable. */ + min_ovf = wi::OVF_OVERFLOW; + max_ovf = wi::OVF_OVERFLOW; + } + } + (if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE) + (plus (convert @0) { wide_int_to_tree (type, cst); } + ))))) +#endif + +/* ((T)(A)) + CST -> (T)(A + CST) */ +#if GIMPLE + (simplify + (plus (convert SSA_NAME@0) INTEGER_CST@1) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0)) + && int_fits_type_p (@1, TREE_TYPE (@0))) + /* Perform binary operation inside the cast if the constant fits + and (A + CST)'s range does not overflow. */ + (with + { + wi::overflow_type min_ovf = wi::OVF_OVERFLOW, + max_ovf = wi::OVF_OVERFLOW; + tree inner_type = TREE_TYPE (@0); + + wide_int w1 = w1.from (wi::to_wide (@1), TYPE_PRECISION (inner_type), + TYPE_SIGN (inner_type)); + + wide_int wmin0, wmax0; + if (get_range_info (@0, &wmin0, &wmax0) == VR_RANGE) + { + wi::add (wmin0, w1, TYPE_SIGN (inner_type), &min_ovf); + wi::add (wmax0, w1, TYPE_SIGN (inner_type), &max_ovf); + } + } + (if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE) + (convert (plus @0 { {wide_int_to_tree (TREE_TYPE (@0), w1)}; }))) + ))) +#endif + /* ~A + A -> -1 */ (simplify (plus:c (bit_not @0) @0) From patchwork Tue Aug 13 08:33:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1146129 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506780-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qcc0QHUu"; dkim-atps=neutral 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 4675fq3t3Yz9sN1 for ; Tue, 13 Aug 2019 18:36:51 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:in-reply-to:references:message-id; q=dns; s= default; b=pAY+WElHSkXtjDUuQSmjwdjlzsdhHoTqd1+ShYiuCjeEhZHfowZHN 6OsL27ZywQmD+Zl8ny3cjweNRC69WNdjr0RKVe5Othu/tsnCGMZNFrZSXaej4tXI bX5eCtYS2xcwrYJi5SqgaFqAPN1LdZT7kZq62pUojAEs0o6Xp5Fb2g= 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:from :to:subject:date:in-reply-to:references:message-id; s=default; bh=xWkA81NUD7IsZnkuIcihYJVIjzw=; b=qcc0QHUuDHgHIL6jtprHtz99R4pR orU3hwms/yewHcH05pthV0guIrAN+DAB/U7TGxaep909/hDckCJyJdqm/UTaqSkn bBJpY/i4rj6wqwt0On1Uu7MNBHFcMevTOdF3QzXTJNyf3NF1OrXrWSYhpoHcKWG3 W942ZRuJ4dlJSFw= Received: (qmail 590 invoked by alias); 13 Aug 2019 08:34:57 -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 500 invoked by uid 89); 13 Aug 2019 08:34:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=5000000000 X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Aug 2019 08:34:54 +0000 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7D8YkT6139124 for ; Tue, 13 Aug 2019 04:34:53 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ubq4n66fm-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 13 Aug 2019 04:34:50 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Aug 2019 09:33:29 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 13 Aug 2019 09:33:28 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7D8XRCP25755890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Aug 2019 08:33:27 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3A16A4064 for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9F594A405C for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) Received: from oc6142347168.ibm.com (unknown [9.152.222.26]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 13 Aug 2019 08:33:27 +0000 (GMT) From: Robin Dapp To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] Add new test cases for wrapped binop simplification. Date: Tue, 13 Aug 2019 10:33:26 +0200 In-Reply-To: <20190813083326.10833-1-rdapp@linux.ibm.com> References: <20190813083326.10833-1-rdapp@linux.ibm.com> x-cbid: 19081308-4275-0000-0000-000003587756 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19081308-4276-0000-0000-0000386A85FF Message-Id: <20190813083326.10833-4-rdapp@linux.ibm.com> X-IsSubscribed: yes --- .../gcc.dg/tree-ssa/copy-headers-5.c | 2 +- .../gcc.dg/tree-ssa/copy-headers-7.c | 2 +- .../gcc.dg/wrapped-binop-simplify-run.c | 52 ++++++++++++++++ .../gcc.dg/wrapped-binop-simplify-signed-1.c | 60 +++++++++++++++++++ .../wrapped-binop-simplify-unsigned-1.c | 36 +++++++++++ 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/wrapped-binop-simplify-run.c create mode 100644 gcc/testsuite/gcc.dg/wrapped-binop-simplify-signed-1.c create mode 100644 gcc/testsuite/gcc.dg/wrapped-binop-simplify-unsigned-1.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c b/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c index 3d9940558cb..7f2e4dc2e4d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-5.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-ch2-details" } */ +/* { dg-options "-O2 -fno-tree-ccp -fno-tree-vrp -fdump-tree-ch2-details" } */ int is_sorted(int *a, int n) { diff --git a/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-7.c b/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-7.c index a0a6e6a9b57..12fca8fd2c4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-7.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/copy-headers-7.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-ch2-details --param logical-op-non-short-circuit=0" } */ +/* { dg-options "-O2 -fdump-tree-ch2-details -fno-tree-ccp -fno-tree-vrp --param logical-op-non-short-circuit=0" } */ int is_sorted(int *a, int n, int m, int k) { diff --git a/gcc/testsuite/gcc.dg/wrapped-binop-simplify-run.c b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-run.c new file mode 100644 index 00000000000..06bf348f1c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-run.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#include +#include + +unsigned int a = 3; +int aa = 3; +int bb = 1; +int cc = 4; + +__attribute__((noinline)) +long foo(int a) +{ + if (a >= -30 && a <= -20) + return (long)(a + 10) + LONG_MAX; +} + +int main() +{ + volatile unsigned long b = (unsigned long)(UINT_MAX + 1) - 1; + assert (b == 18446744073709551615ul); + + volatile unsigned long c = (unsigned long)(a - 4) + 1; + assert (c == 4294967296); + + volatile unsigned long d = (unsigned long)(a + UINT_MAX - 4) + 2; + assert (d == 4294967296); + + volatile unsigned long e = (unsigned long)(a - UINT_MAX) + UINT_MAX; + assert (e == 4294967299); + + volatile unsigned long f = (unsigned long)(a + UINT_MAX) - UINT_MAX; + assert (f == 18446744069414584323ul); + + volatile long g = (long)(a - 4) + 1; + assert (g == 4294967296); + + volatile long h = (long)(aa + UINT_MAX) + 1; + assert (h == 3); + + /* Zero-extend. */ + volatile unsigned long i = (unsigned long)(bb + 4294967294u) + 5000000000; + assert (i == 9294967295); + + /* Sign-extend. */ + volatile unsigned long j = (unsigned long)(cc + 4294967294u) + 8000000000; + assert (j == 8000000002); + + volatile unsigned long k = foo (-25); + assert (k == 9223372036854775792l); +} diff --git a/gcc/testsuite/gcc.dg/wrapped-binop-simplify-signed-1.c b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-signed-1.c new file mode 100644 index 00000000000..19b787b61b2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-signed-1.c @@ -0,0 +1,60 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details" } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to" 11 "ccp1" } } */ + +#include + +long foo(int a) +{ + return (long)(a - 2) + 1; +} + +long bar(int a) +{ + return (long)(a + 3) - 1; +} + +long baz(int a) +{ + return (long)(a - 1) + 2; +} + +long baf(int a) +{ + return (long)(a + 1) - 2; +} + +long bak(int a) +{ + return (long)(a + 1) + 3; +} + +long bal(int a) +{ + return (long)(a - 7) - 4; +} + +long bam(int a) +{ + return (long)(a - 1) - INT_MAX; +} + +long bam2(int a) +{ + return (long)(a + 1) + INT_MAX; +} + +long ban(int a) +{ + return (long)(a - 1) + INT_MIN; +} + +long ban2(int a) +{ + return (long)(a + 1) - INT_MIN; +} + +unsigned long baq(int a) +{ + return (unsigned long)(a + 1) - 1; +} diff --git a/gcc/testsuite/gcc.dg/wrapped-binop-simplify-unsigned-1.c b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-unsigned-1.c new file mode 100644 index 00000000000..71ab0807d7e --- /dev/null +++ b/gcc/testsuite/gcc.dg/wrapped-binop-simplify-unsigned-1.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ccp1-details -fdump-tree-evrp-details -fdump-tree-vrp1-details" } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to" 1 "ccp1" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to" 2 "evrp" } } */ +/* { dg-final { scan-tree-dump-times "gimple_simplified to" 2 "vrp1" } } */ + +#include + +unsigned long foo(unsigned int a) +{ + if (a > 3 && a < INT_MAX - 100) + return (unsigned long)(a - 1) + 1; +} + +unsigned long bar(unsigned int a) +{ + if (a > 3 && a < INT_MAX - 100) + return (unsigned long)(a + 1) + ULONG_MAX; +} + +unsigned long baz(unsigned int a) +{ + if (a > 3 && a < INT_MAX - 100) + return (unsigned long)(a + 1) - 5; +} + +long baf(unsigned int a) +{ + if (a > 3 && a < INT_MAX - 100) + return (long)(a - 1) + 1; +} + +unsigned long baq(int a) +{ + return (unsigned long)(a - 2) + 1; +}