From patchwork Thu Jun 27 04:29:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 254945 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 837382C0097 for ; Thu, 27 Jun 2013 14:29:41 +1000 (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:subject:content-type; q= dns; s=default; b=X4hns8o6AaDfBVJjADnXZu/oRvaYscZiGLTQaVOv45T6vT eUliVDcVMiHsDiOgu922nygC8Yc+RHlv1nnQISe3EGT/YZ2hgoF88do3OsnPpeAV egsU9BxPXFi/le1C6qzNMoSUKG3WFNMMG5RLaH9/yyB0YTVLuC1PWJ5FIr8sQ= 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:subject:content-type; s= default; bh=8ee0DGIARso4Mm8TY7eFnqTIFuU=; b=pbydiKv2JZyo7GDUzftK cTk5MzrbFo6q0IeeB1f+Fk7WCcg3TP0cMLb3ELXgggNkGiJR9VgAJMcN2GrFUxsl NJss955RCmqb/OrBfE1N1cDWOyG0bcMCMO8jvztWr9A/Apwj3dWR8YOJxwEZTKZy htbSTzgPWSl7seV14avaCj4= Received: (qmail 32238 invoked by alias); 27 Jun 2013 04:29:34 -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 32180 invoked by uid 89); 27 Jun 2013 04:29:30 -0000 X-Spam-SWARE-Status: No, score=-7.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 27 Jun 2013 04:29:29 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5R4TSli024406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 27 Jun 2013 00:29:28 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-62.phx2.redhat.com [10.3.113.62]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5R4TRHe022206 for ; Thu, 27 Jun 2013 00:29:28 -0400 Message-ID: <51CBBFA7.9010808@redhat.com> Date: Wed, 26 Jun 2013 22:29:27 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130612 Thunderbird/17.0.6 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH] Improve jump threading using VRP information X-Virus-Found: No Just something else I saw while analyzing dumps from an unrelated set of changes. It's relatively common to see sequences like this: # parent_1 = PHI _11 = single_tree_10(D) != 0; _12 = parent_1 == 0B; _13 = _11 & _12; if (_13 != 0) goto ; else goto ; Where VRP can deduce that the value of parent_6 has a nonzero value on one (or more) of the paths reaching this block (because those paths dereference parent_6). Obviously when VRP knows parent_6 is nonzero, then we know the current block will always transfer control to BB 7. Or something like this: : # prephitmp_49 = PHI <1(4), pretmp_48(5)> prev_line.31_6 = prev_line; _8 = prev_line.31_6 != line_7(D); line_differs_9 = (unsigned char) _8; _10 = prephitmp_49 | line_differs_9; if (_10 != 0) goto ; else goto ; We may not know the exact value of _10, but VRP can determine that when BB6 is reached from BB4 that BB6 will always transfer control to BB8. I never coded up the bits to utilize VRP information to simplify statements for threading except for COND_EXPRs. It wasn't clear how often it would be useful, thus I took the easy way out. This picks up a hundred or so additional threading opportunities in my testfiles. Not huge, but worth it IMHO. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. OK for trunk? * tree-vrp.c (simplify_stmt_for_jump_threading): Try to simplify assignments too. If the RHS collapses to a singleton range, then return the value for the range. * gcc.dg/tree-ssa/ssa-vrp-thread-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c new file mode 100644 index 0000000..9d9473e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp1-details" } */ + + +struct basic_block_def; +typedef struct basic_block_def *basic_block; +enum gimple_code +{ + LAST_AND_UNUSED_GIMPLE_CODE +}; +struct omp_region +{ + struct omp_region *outer; + basic_block cont; +}; +void +build_omp_regions_1 (basic_block bb, struct omp_region *parent, + unsigned char single_tree, enum gimple_code code) +{ + if (code == 25) + parent = parent->outer; + else if (code == 42) + parent->cont = bb; + if (single_tree && !parent) + return; + oof (); +} + +/* { dg-final { scan-tree-dump-times "Threaded" 1 "vrp1" } } */ +/* { dg-final { cleanup-tree-dump "vrp1" } } */ + diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index ec7ef8f..683a3db 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -9109,15 +9109,27 @@ static vec equiv_stack; static tree simplify_stmt_for_jump_threading (gimple stmt, gimple within_stmt) { - /* We only use VRP information to simplify conditionals. This is - overly conservative, but it's unclear if doing more would be - worth the compile time cost. */ - if (gimple_code (stmt) != GIMPLE_COND) - return NULL; + if (gimple_code (stmt) == GIMPLE_COND) + return vrp_evaluate_conditional (gimple_cond_code (stmt), + gimple_cond_lhs (stmt), + gimple_cond_rhs (stmt), within_stmt); + + if (gimple_code (stmt) == GIMPLE_ASSIGN) + { + value_range_t new_vr = VR_INITIALIZER; + tree lhs = gimple_assign_lhs (stmt); + + if (TREE_CODE (lhs) == SSA_NAME + && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || POINTER_TYPE_P (TREE_TYPE (lhs)))) + { + extract_range_from_assignment (&new_vr, stmt); + if (range_int_cst_singleton_p (&new_vr)) + return new_vr.min; + } + } - return vrp_evaluate_conditional (gimple_cond_code (stmt), - gimple_cond_lhs (stmt), - gimple_cond_rhs (stmt), within_stmt); + return NULL_TREE; } /* Blocks which have more than one predecessor and more than