From patchwork Tue Dec 11 04:56:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1010840 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-492045-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="woes55tu"; 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 43DSNK1R4vz9s3l for ; Tue, 11 Dec 2018 15:57:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=p3UWLVrMw17VLDsd3tumemj1yosj6UJu6xcpdcOlwXshcG+V/Q fIVwaNJqeEhZ9n9mefStkLwZ5AsTpYK3cxAnorn+CyFH5lCjR3Rg/dp39X8h4SLv Yw18XbaCd7dHRCwRwEkydxoEeBOgLQFtMXo00q8Kpx3jJx7s1Pa588/Jg= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=32J2vTob06MgeMc7QZ4pnwtASmM=; b=woes55tulETcYYaQ1Pxq W3fsDJOlB6/VW134K0evwbrO4qqMburaaEr2cDKGNYo4A/vI3+xcWr1ttNIwOXYa wefFd/+2OJdFP+kh51U4TFmXUkx0b0W1UbEAqVwfBfB+YOWcRrWOm2eiJbT2UEvQ QAPzrX0elyUwgiuEru29yR0= Received: (qmail 13703 invoked by alias); 11 Dec 2018 04:56:53 -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 13050 invoked by uid 89); 11 Dec 2018 04:56:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=exposed 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; Tue, 11 Dec 2018 04:56:50 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68D093082E4F for ; Tue, 11 Dec 2018 04:56:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-17.rdu2.redhat.com [10.10.112.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B5BC60BF1 for ; Tue, 11 Dec 2018 04:56:47 +0000 (UTC) To: gcc-patches From: Jeff Law Subject: [committed] [PR tree-optimization/80520] Throttle path splitting slightly. Openpgp: preference=signencrypt Message-ID: <2bac4239-d7ef-7555-a362-cfddc6bde931@redhat.com> Date: Mon, 10 Dec 2018 21:56:46 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 X-IsSubscribed: yes This is a pre-req for fixing 80520. Essentially the goal here is to keep the key code in this form: [ ... ] if (_20 != 0) goto ; [50.00%] else goto ; [50.00%] [local count: 531502203]: _18 = _25 ^ 2567483615; [local count: 1063004407]: # prephitmp_49 = PHI <_25(3), _18(4)> _2 = (void *) ivtmp.8_30; MEM[base: _2, offset: 0B] = prephitmp_49; ivtmp.8_29 = ivtmp.8_30 + 8; if (ivtmp.8_29 != _6) goto ; [98.99%] else goto ; [1.01%] Split-paths wants to duplicate bb5 into bb4. It's just not all that profitable to do so. We can get ever-so-slightly better code on a target like microblaze and perhaps others with delay slots and no conditional move/execution capabilities. But that seems more like something we should be tackling at the RTL level. To finish fixing 80520 we will need to improve the RTL if-conversion where we presumably can cost things and make a good choice between the branchy code we have vs straightline code with a conditional move or conditional execution. I'm not tackling that yet. Note that split-path-5 has the same basic structure. A half-diamond with a single statement in the middle block that should be trivially if-convertable if profitable. So I adjusted that testcase. Bootstrapped and regression tested on x86_64. Installing on the trunk momentarily. commit d90b13427e4940adabc4320c68ca88513dee2eef Author: Jeff Law Date: Mon Dec 10 21:46:41 2018 -0700 PR tree-optimization/80520 * gimple-ssa-split-paths.c (is_feasible_trace): Recognize half diamonds that are likely if convertable. * gcc.dg/tree-ssa/split-path-5.c: Update expected output. * gcc.dg/tree-ssa/split-path-11.c: New test. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 14c52ad64be..eddcdc3f843 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-12-10 Jeff Law + + PR tree-optimization/80520 + * gimple-ssa-split-paths.c (is_feasible_trace): Recognize half + diamonds that are likely if convertable. + 2018-12-10 Martin Sebor PR tree-optimization/86196 diff --git a/gcc/gimple-ssa-split-paths.c b/gcc/gimple-ssa-split-paths.c index a8515119ce5..91596526045 100644 --- a/gcc/gimple-ssa-split-paths.c +++ b/gcc/gimple-ssa-split-paths.c @@ -203,6 +203,98 @@ is_feasible_trace (basic_block bb) } } + /* Canonicalize the form. */ + if (num_stmts_in_pred1 == 0 && num_stmts_in_pred2 == 1) + { + std::swap (pred1, pred2); + std::swap (num_stmts_in_pred1, num_stmts_in_pred2); + } + + /* Another variant. This one is half-diamond. */ + if (num_stmts_in_pred1 == 1 && num_stmts_in_pred2 == 0 + && dominated_by_p (CDI_DOMINATORS, pred1, pred2)) + { + gimple *stmt1 = last_and_only_stmt (pred1); + + /* The only statement in PRED1 must be an assignment that is + not a good candidate for if-conversion. This may need some + generalization. */ + if (stmt1 && gimple_code (stmt1) == GIMPLE_ASSIGN) + { + enum tree_code code1 = gimple_assign_rhs_code (stmt1); + + if (!poor_ifcvt_candidate_code (code1)) + { + tree lhs1 = gimple_assign_lhs (stmt1); + tree rhs1 = gimple_assign_rhs1 (stmt1); + + gimple_stmt_iterator gsi; + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *phi = gsi_stmt (gsi); + if ((gimple_phi_arg_def (phi, 0) == lhs1 + && gimple_phi_arg_def (phi, 1) == rhs1) + || (gimple_phi_arg_def (phi, 1) == lhs1 + && gimple_phi_arg_def (phi, 0) == rhs1)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Block %d appears to be a join point for " + "if-convertable half-diamond.\n", + bb->index); + return false; + } + } + } + } + } + + /* Canonicalize the form. */ + if (num_stmts_in_pred1 == 0 && num_stmts_in_pred2 == 1) + { + std::swap (pred1, pred2); + std::swap (num_stmts_in_pred1, num_stmts_in_pred2); + } + + /* Another variant. This one is half-diamond. */ + if (num_stmts_in_pred1 == 1 && num_stmts_in_pred2 == 0 + && dominated_by_p (CDI_DOMINATORS, pred1, pred2)) + { + gimple *stmt1 = last_and_only_stmt (pred1); + + /* The only statement in PRED1 must be an assignment that is + not a good candidate for if-conversion. This may need some + generalization. */ + if (stmt1 && gimple_code (stmt1) == GIMPLE_ASSIGN) + { + enum tree_code code1 = gimple_assign_rhs_code (stmt1); + + if (!poor_ifcvt_candidate_code (code1)) + { + tree lhs1 = gimple_assign_lhs (stmt1); + tree rhs1 = gimple_assign_rhs1 (stmt1); + + gimple_stmt_iterator gsi; + for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *phi = gsi_stmt (gsi); + if ((gimple_phi_arg_def (phi, 0) == lhs1 + && gimple_phi_arg_def (phi, 1) == rhs1) + || (gimple_phi_arg_def (phi, 1) == lhs1 + && gimple_phi_arg_def (phi, 0) == rhs1)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Block %d appears to be a join point for " + "if-convertable half-diamond.\n", + bb->index); + return false; + } + } + } + } + } + /* If the joiner has no PHIs with useful uses there is zero chance of CSE/DCE/jump-threading possibilities exposed by duplicating it. */ bool found_useful_phi = false; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 43675b9adb0..0fde3cb395a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-12-10 Jeff Law + + PR tree-optimization/80520 + * gcc.dg/tree-ssa/split-path-5.c: Update expected output. + * gcc.dg/tree-ssa/split-path-11.c: New test. + 2018-12-10 Steven G. Kargl PR fortran/97922 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c new file mode 100644 index 00000000000..f94f1a84e2c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-11.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details -w" } */ + +void foo(unsigned long *M) +{ + for (unsigned long k = 0; k < 227; ++k) + { + unsigned long y = + ((M[k] & 0xffffffff80000000) | (M[k + 1] & 0x7fffffff)); + M[k] = (M[k + 397] ^ (y >> 1) ^ ((y & 1) ? 2567483615 : 0)); + } +} + +/* { dg-final { scan-tree-dump-times "join point for if-convertable half-diamond" 1 "split-paths" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/split-path-5.c b/gcc/testsuite/gcc.dg/tree-ssa/split-path-5.c index 95aabdaf6be..83141a716ed 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/split-path-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/split-path-5.c @@ -41,4 +41,4 @@ bmhi_init (const char *pattern) } } -/* { dg-final { scan-tree-dump-times "Duplicating join block" 1 "split-paths" } } */ +/* { dg-final { scan-tree-dump-times "join point for if-convertable half-diamond" 1 "split-paths" } } */